在js中发送ajax请求时,回调函数常用的有success和error,其中success的参数返回值data,即为返回对象;
但是,error(常用接收系统抛出的异常信息)的返回值data格式与success的不同,还有一些其他的参数,例如:
var ajax = new $ax(Feng.ctxPath + "/yuntaiFill/update",
function(data){
alert("success:"+JSON.stringify(data));
},
function(data){
alert("error:"+JSON.stringify(data));
});
ajax.set(this.yuntaiFillInfoData);
ajax.start();
success的打印结果为:
success:{"@type":"com.stylefeng.guns.common.constant.tips.SuccessTip","code":200,"message":"操作成功"}
error的打印结果为:
error:{"readyState":4,
"responseText":"{\n\t\"@type\":\"com.stylefeng.guns.common.constant.tips.ErrorTip\",\n\t\"code\":400,\n\t\"message\":\"业务类型重复,请重新输入\"\n}",
"responseJSON":{"@type":"com.stylefeng.guns.common.constant.tips.ErrorTip","code":400,"message":"业务类型重复,请重新输入"},"status":500,"statusText":"error"}
error的参数包含了success的返回参数,并放入了“responseJSON”中,所以使用的时候需要注意。