web ajax跨域问题解决方案
2024-08-26 10:01:17
jsonpHandler({
"code": "aaa",
"price": 1780,
"tickets": 5
}); //后端发过来的josnp格式,jsonpHandler必须和ajax中的jsonpCallback的参数相同,
//此参数可以从前端传过来的参数中获取到(一般情况参数名是:callback)
$.ajax({
type:"POST",
url:"yourUrl",
data:{},
dataType:"jsonp",
timeout:6000,
jsonpCallback:"jsonpHandler",
error:function(XMLHttpRequest,textStatus,errorThrown){
if(textStatus=="timeout"){
alert('抱歉!请求超时,请重试!或请检查您的网络状况!');
return false;
}else if(textStatus=="error"||textStatus=="parsererror"){
alert('抱歉!系统发生错误,请重试!');
console.log(errorThrown);
return false;
}else if(textStatus=="abort"){
alert('抱歉!程序发生中断,请重试!');
return false;
}
},
complete:function(){ },
beforeSend:function(){ },
success:function(backData,textStatus){
console.log(backData);
}
});
最新文章
- DevExtreme 学习应用[2]
- 一个js获取数组下标的函数
- strcpy和memcpy的区别(转载)
- c#多态之抽象类与接口的一点收获~~
- 无法查找或打开pdb文件
- ld: library not found for -lPods-AFNetworking
- leecode 每日解题思路 102-Binary Tree Level Order Traversal
- Uva 122 树的层次遍历 Trees on the level lrj白书 p149
- 2017春 前端自动化(二) 页面自动刷新、sass与css转换的使用、pxToRem直观转换
- HanLP自然语言处理包介绍
- Eclipse maven 错误修正方法:An error occurred while filtering resources
- 为什么说Thunderbird是最好的桌面RSS阅读器
- github开源库(二)
- Android------------fragment数据传递
- 1217. [HNOI2003]消防局的设立【贪心】
- Tomcat与Spring中的事件机制详解
- tensorflow高级库
- Linux VPS主机利用Crontab实现定时重启任务
- 【luogu P1825 [USACO11OPEN]玉米田迷宫Corn Maze】 题解
- embedded tomcat运行java web,Unable to compile class for JSP
热门文章
- Wow! Such Doge! - HDU 4847 (水题)
- M - 昂贵的聘礼 - poj1062
- angularJS 服务三
- C#中操作WMI的类库-实现远程登录共享
- ";Storage Virtualization"; VS ";Software-Defined Storage";
- Ruby On Rails 4 hello world,Ruby On Rails上手
- PHP安全编程:不要让不相关的人看到报错信息(转)
- Day7 - Python基础7 面向对象编程进阶
- AlertDialog dismiss 和 cancel方法的区别
- codevs 1993 草地排水 USACO