劳驾老师看一下为什么会报错显示不出来呢

来源:3-6 自由编程

TOUU_JP

2020-10-11 12:19:44

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-3.5.1.js"></script>
<script type="text/javascript">
        $(function(){
            $("input".click(function(){
                var index = $(this).attr("value");
                $.ajax({
                    "url" : "/EmployeeList/EmployeeList" ,
                    "type" : "get" ,
                    "data" : {"jso" : index} ,
                    "data-type" : "json" ,
                    "success" : function(json){
                        $("#dis").html("");
                        $("#dis").html(json);
                    }
                });
            });
        });
    </script>
</head>
<body>
    <form action="so">
        <input type="button" value="流行歌曲" name="input" style="width: 500px">
        <input type="button" value="经典歌曲" name="input" style="width: 500px">
        <input type="button" value="摇滚歌曲" name="input" style="width: 500px">
        <div id="dis" name="song"></div>
    </form>
</body>
</html>

package com.immoc.ajax;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

/**
 * Servlet implementation class EmployeeList
 */
@WebServlet("/EmployeeList")
public class EmployeeList extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public EmployeeList() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
//        List list = new ArrayList();
//        list.add("小红<br>小明<br>小白");
//        list.add("职员<br>经理");
//        list.add("人事部<br>技术部<br>无线事业部");
//        String json = JSON.toJSONString(list);
//        response.setContentType("text/html;charset=UTF-8");
//        response.getWriter().println(json);
        List list1 = new ArrayList();
        String type = request.getParameter("jso");
        if (type != null && type.equals("流行歌曲")) {
            list1.add("稻香<br>晴天<br>告白气球");
        }
        else if(type != null && type.equals("经典歌曲")) {
            list1.add("千千阙歌<br>傻女<br>七友");
        }
        else if(type != null && type.equals("摇滚歌曲")) {
            list1.add("一块红布<br>假行僧<br>新长征路上的摇滚");
        }else {
            list1.add("无");
        }
        String json1 = JSON.toJSONString(list1);
        System.out.println(json1);
        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().println(json1);
    }

}


写回答

2回答

好帮手慕小尤

2020-10-11

同学你好,建议同学将data-type修改为dataType。如下所示:

http://img.mukewang.com/climg/5f82c8b409fb38fd04610219.jpg

祝学习愉快!

0

好帮手慕小尤

2020-10-11

同学你好,同学在$("input"处缺少一个括号,建议同学添加后,清除缓存重新进行测试。如下所示:

http://img.mukewang.com/climg/5f82c8cf09c0006104540268.jpg

http://img.mukewang.com/climg/5f82acea09d4a1e502400228.jpg

祝学习愉快!

0
hOUU_JP
h 老师 显示出来了 不过为什么返回到画面上会带[""]呢 如何可以去掉?
h020-10-11
共1条回复

0 学习 · 9666 问题

查看课程