Ajax功能无法正常工作

时间:2018-04-18 07:24:20

标签: javascript java ajax spring-mvc

我是ajax的新手。我用spring MVC编写了ajax函数,后端函数。当我运行代码ajax函数调用后端函数并正确返回数据但是ajax函数调用

error : function(e) {
            console.log("ERROR: "+ e);
        },
不打电话     成功:函数(数据){     }

这是我的ajax功能

$.ajax({
        type : "POST",
        contentType : "application/json",
        url : "getAllDansalJSON.html",
        data:"", 
        dataType : 'json',
        timeout : 10000,
        success : function(data) {
            alert(data);
            alert(data.message);
            if (data.message=="SUCCESS") {
                alert(data);
                setMarkers(map);
            }
             else {
                alert("ERROR");
            }
        },
        error : function(e) {
            console.log("ERROR: "+ e);
        },
        done : function(x) {
            console.log("DONE");
        }
    });

这是我的后端功能

@RequestMapping(value = "/getAllDansalJSON", method=RequestMethod.POST )
public @ResponseBody DansalaJSONRespons  getAccountBalance() {
    DansalaJSONRespons dansalaJSONRespons=new DansalaJSONRespons();
    try{

        List<DansalaBean> list= dansalaDAO.getDansalList();
        dansalaJSONRespons.setDansalAllList(list);
        dansalaJSONRespons.setMessage("SUCCESS");
    }

    catch(Exception e){
        dansalaJSONRespons.setMessage("INVALID");
    }
    return dansalaJSONRespons;


}

1 个答案:

答案 0 :(得分:0)

我更改了网址:&#34; getAllDansalJSON.html&#34; ---&GT; url:&#34; getAllDansalJSON.json&#34;

$.ajax({
    type : "POST",
    contentType : "application/json",
    url : "getAllDansalJSON.json",
    data:"", 
    dataType : 'json',
    timeout : 10000,
    success : function(data) {
        alert(data);
        alert(data.message);
        if (data.message=="SUCCESS") {
            alert(data);
            setMarkers(map);
        }
         else {
            alert("ERROR");
        }
    },
    error : function(e) {
        console.log("ERROR: "+ e);
    },
    done : function(x) {
        console.log("DONE");
    }
});
相关问题