我是 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"); 
    } 
}); 


评论关闭
IT源码网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!