jQuery跨域请求解决方法
2010-10-14 16:52
393 查看
var xmlHttp = false;
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
function sendRequest(p){
var url = "aaa.bbb.com";
xmlHttp.open("GET", url, true);
//xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null);
}
如果当前站点域名和请求的站点不属于同一个域名,会提示"没有权限",即限制跨域访问。
可以通过这种方式解决:
function sendRequest(p){
var url = "aaa.bbb.com";
$.ajax({
async:false,
url:url,
type:"GET",//POST不支持跨域
dataType:"jsonp",
jsonp: 'jsoncallback',
data: "",
timeout: 100
});
}
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e2) {
xmlHttp = false;
}
}
if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
xmlHttp = new XMLHttpRequest();
}
function sendRequest(p){
var url = "aaa.bbb.com";
xmlHttp.open("GET", url, true);
//xmlHttp.onreadystatechange = updatePage;
xmlHttp.send(null);
}
如果当前站点域名和请求的站点不属于同一个域名,会提示"没有权限",即限制跨域访问。
可以通过这种方式解决:
function sendRequest(p){
var url = "aaa.bbb.com";
$.ajax({
async:false,
url:url,
type:"GET",//POST不支持跨域
dataType:"jsonp",
jsonp: 'jsoncallback',
data: "",
timeout: 100
});
}
相关文章推荐
- 前端使用Jquery的getJSON方法,后台使用PHP,解决IE和火狐Firefox中存在的跨域ajax请求问题。
- jquery的ajax跨域请求jsonp解决方法
- jquery $.get() $.post 跨域请求cors解决方法
- Nginx反向代理、CORS、JSONP等跨域请求解决方法总结
- 客户端ajax请求为实现Token验证添加headers后导致正常请求变为options跨域请求解决方法
- 浅析jsopn跨域请求原理及cors(跨域资源共享)的完美解决方法
- Javascript跨域请求的几种解决方法
- jquery使用$.getJson()跨域大数据量请求方法
- vue-cli的axios使用方法,get、post请求的跨域问题解决
- Ajax请求Session超时的解决办法:拦截器 + 封装jquery的post方法
- jquery中ajax请求后台数据成功后既不执行success也不执行error的完美解决方法
- 关于jquery跨域请求方法
- jQuery 跨域请求出错 XMLHttpRequest cannot load 解决办法
- WebApi Ajax 跨域请求解决方法(CORS实现)
- Ajax请求Session超时的解决办法:拦截器 + 封装jquery的post方法
- WCF Restful JQuery 跨域解决方法
- php解决跨域请求的三种方法
- 跨域请求解决方法(JSONP, CORS)
- jQuery 跨域访问问题解决方法
- Nginx反向代理、CORS、JSONP等跨域请求解决方法总结