gpt4 book ai didi

javascript - Ajax功能无法正常工作

转载 作者:太空宇宙 更新时间:2023-11-04 10:31:56 24 4
gpt4 key购买 nike

我是 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;


}

最佳答案

我更改了 url:"getAllDansalJSON.html"---> url :"getAllDansalJSON.json"

$.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");
}
});

关于javascript - Ajax功能无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49893586/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com