-
Ajax请求代码:
mui.ajax('http://localhost:8888/istock/api.jsp',{
data:{
code: "MS0001",
token: "un=admin&up=admin",
data: "un=admin&up=admin&query=2015-03-25&desc=用户登录测试"
},
dataType:'json',//服务器返回json格式数据
type:'get',//HTTP请求类型
timeout:6000,//超时时间设置为10秒;
success:function(data){
//服务器返回响应,根据响应结果,分析是否登录成功;
data = JSON.stringify(data);
console.log('success:::' + data);
alert(data);
},
error:function(xhr,type,errorThrown){
//异常处理;
console.log(type);
alert(type);
}
}); -
服务器端jsp响应输出:
String code = request.getParameter("code")==null?"":request.getParameter("code").toString();
String token = request.getParameter("token")==null?"":request.getParameter("token").toString();
String data = request.getParameter("data")==null?"":request.getParameter("data").toString();String json = API.api(new RequestArgs(code,token,data));
//json
response.setHeader("Access-Control-Allow-Origin", "*");
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control", "no-cache");
java.io.PrintWriter pw = null;
try{
pw = response.getWriter();
pw.write(json);
}catch (Exception e){
out.println("Error...");
}finally{
pw.close();
} -
浏览器错误提示:
XMLHttpRequest cannot load http://localhost:8888/istock/api.jsp?code=MS0001&token=un%3Dadmin%26up%3Dad…2015-03-25%26desc%3D%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95%E6%B5%8B%E8%AF%95. Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers.
api.js:56 abort -
服务器拦截到请求数据:
HTTP API POST: {} {"apiCode":"MS0001","apiToken":"un=admin&up=admin","argsData":"un=admin&up=admin&query=2015-03-25&desc=用户登录测试"}
请教这是什么问题呢?mui.ajax的 error:function 回调函数拦截到了错误信息。为什么服务器已经拦截到请求,并处理了,却接收不到呢?
后海 (作者)
对头,
2015-08-05 15:57
一朵羊毛飞上天
除了127.0.0.1和localhost还有什么本机地址吗?
2016-08-03 11:10
6***@qq.com
回复 一朵羊毛飞上天:使用win+r的运行框,输入IPCONFIG就可以查询到自己在局域网中的IP地址
2018-06-26 21:05
6***@qq.com
终于解决了!!感谢你,挥泪感谢
2018-06-26 21:06
9***@qq.com
对头,我用Hbuiler请求本机数据库,一直error报type=abort,把url改成本机其他ip就成功了!
2018-09-06 16:38
9***@qq.com
回复 一朵羊毛飞上天:用ipconfig查看本机IPv4地址!
2018-09-06 16:40