Dav*_*ver 76 javascript jquery cross-domain
根据带有凭据的请求,Firefox只会发送凭据以及跨域帖子
invocation.withCredentials = "true";
设置...但似乎jQuery的Ajax API没有为此提供任何机制.
有没有我错过的东西?还有其他方法可以做到吗?
Kan*_*gur 156
功能应该在jQuery 1.5中被打破.
从jQuery 1.5.1开始,你应该使用xhrFields param.
$.ajaxSetup({
type: "POST",
data: {},
dataType: 'json',
xhrFields: {
withCredentials: true
},
crossDomain: true
});
Run Code Online (Sandbox Code Playgroud)
文档:http://api.jquery.com/jQuery.ajax/
报告错误:http://bugs.jquery.com/ticket/8146
Dou*_*ner 39
您可以使用beforeSend回调来设置其他参数(该XMLHTTPRequest对象作为唯一参数传递给它).
您知道,这种类型的跨域请求在普通站点方案中不起作用,而在任何其他浏览器中都不起作用.我甚至都不知道FF 3.5所施加的安全限制,所以你不要无所事事地撞到墙上:
$.ajax({
url: 'http://bar.other',
data: { whatever:'cool' },
type: 'GET',
beforeSend: function(xhr){
xhr.withCredentials = true;
}
});
Run Code Online (Sandbox Code Playgroud)
还有一件事需要注意,jQuery是为了规范浏览器差异而设置的.您可能会发现禁止此类功能的jQuery库会施加进一步的限制.
| 归档时间: |
|
| 查看次数: |
137684 次 |
| 最近记录: |