jquery ajax post 跨域访问带cookie
2016-08-17 20:57
447 查看
js:
//显示用户信息
$.ajax("http://ltest.com:2020/test/",{
//提交数据的类型 POST GET
type:"POST",
async:false,
data:{ 'username': username.value, 'password': userpassw.value },
crossDomain:true,
datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
xhrFields: { withCredentials: true },
//成功返回之后调用的函数
success:function(data,status,xhr){
if(data["state"]==1)
{
alert("ok");
}else{
alert("密码或用户名错误");
}
}
});
服务端要加头:
Access-Control-Allow-Origin 不能为“*“,当withCredentials为真是
resp['Access-Control-Allow-Origin'] = req.META.get("HTTP_ORIGIN")
“true”不要写成“True”了,浏览器不认
resp["Access-Control-Allow-Credentials"] = "true"
//显示用户信息
$.ajax("http://ltest.com:2020/test/",{
//提交数据的类型 POST GET
type:"POST",
async:false,
data:{ 'username': username.value, 'password': userpassw.value },
crossDomain:true,
datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
xhrFields: { withCredentials: true },
//成功返回之后调用的函数
success:function(data,status,xhr){
if(data["state"]==1)
{
alert("ok");
}else{
alert("密码或用户名错误");
}
}
});
服务端要加头:
Access-Control-Allow-Origin 不能为“*“,当withCredentials为真是
resp['Access-Control-Allow-Origin'] = req.META.get("HTTP_ORIGIN")
“true”不要写成“True”了,浏览器不认
resp["Access-Control-Allow-Credentials"] = "true"
相关文章推荐
- 360浏览器 7.1版本兼容模式,jQuery $.post 和$.ajax 跨域访问失效
- 不断的跨域访问的时候,如果jquery,ajax都没办法解决的时候,用下面这个吧:
- JQuery+ajax+jsonp 跨域访问
- 浅谈JQuery+ajax+jsonp 跨域访问
- JQuery+ajax+jsonp 跨域访问
- [经验] - JQuery.Ajax + 跨域 (crossDomain) + POST + JSON + WCF RESTful, 5大陷阱和解决方案
- JQuery+ajax+jsonp 跨域访问
- Jquery,ajax 跨域访问
- JQuery+ajax+jsonp 跨域访问
- 浅谈JQuery+ajax+jsonp 跨域访问
- Jquery版Ajax利用JSONP 跨域POST/GET传输数据研究
- JQuery+ajax+jsonp 跨域访问
- JS JQuery Ajax 跨域 Post Soap webservice
- JQuery+ajax+jsonp 跨域访问
- 使用jquery中的ajax进行跨域访问
- JQuery+ajax+jsonp 跨域访问
- JQuery+ajax+jsonp 跨域访问
- 跨域解决方案之一---->JQuery.Ajax JSONP解决跨域访问
- ajax 设置Access-Control-Allow-Origin实现跨域访问 post
- 跨域解决方案之一---->JQuery.Ajax JSONP解决跨域访问