以下适用于IE以外的所有浏览器(我在IE 9中测试).
jQuery.support.cors = true;
...
$.ajax(
url + "messages/postMessageReadByPersonEmail",
{
crossDomain: true,
data: {
messageId : messageId,
personEmail : personEmail
},
success: function() {
alert('marked as read');
},
error: function(a,b,c) {
alert('failed');
},
type: 'post'
}
);
Run Code Online (Sandbox Code Playgroud)
我有另一个使用的函数dataType: 'jsonp',但我不需要在这个AJAX调用上返回任何数据.我的最后一招将是返回JSONP中包含的一些乱码,以使其正常工作.
任何想法为什么IE搞砸了没有返回数据的CORS请求?
我发现这个代码可以使用setRequestheader和Ajax进行身份验证.
this.xmlDoc.setRequestHeader('Authorization','Basic ' + Base64.encode("User:Password"));
Run Code Online (Sandbox Code Playgroud)
不幸的是,我不知道Ajax和Base64似乎不是我可以引用的类或方法.这种基本加密有替代方案吗?或者我可以从Javascript调用的simular编码函数?
谢谢 !
我的Ajax跨域请求在IE 9中失败,并且"拒绝访问".我已经阅读了几篇关于这个主题的帖子,AFAIK应该可以使用.
async,jsonp并且crossdomain,cache是false.这些是我找到的先决条件.jQuery.support.cors 是真的Access-Control-Allow-Origin:*(SO)那么为什么这会因拒绝访问而失败?任何的想法?可能是因为我的代码是从"JavaScript"库中调用的,而不是<script></script>页面上的标签吗?
我错过了什么?
// The code is part of an object's method (prototype)
// code resides in a library "Mylib.js"
$.ajax({
type: 'GET',
url: url,
cache: false,
async: true,
crossdomain: true, // typo, crossDomain, see my answer below
datatype: "jsonp", // dataType
success: function (data, status) {
if (status == "success" && !Object.isNullOrUndefined(data)) …Run Code Online (Sandbox Code Playgroud)