我有一个脚本,它向远程服务器发出ajax请求,返回纯文本响应.除了IE8(震撼)之外,它在所有浏览器中都能正常工作.
这是代码:
$.ajax({
url: 'abc.com/?somerequest=somevalue',
cache: false,
type: 'POST',
data:{
sub: 'uploadprogress',
uploadid: this.uploadId
},
dataType: 'html',
success: this.uploadProgressResp,
error: this.errorResp
});
Run Code Online (Sandbox Code Playgroud)
在IE8中,它返回"无传输"错误.我想这是因为IE8不允许跨域请求?
注意:我没有为远程服务器编写API.如果我这样做,我会返回JSON响应而不是纯文本响应.所以是的,dataType应该是HTML而不是JSON.
我在SCRIPT5上阅读了很多其他文章:在IE9中访问被拒绝的问题,但据我所知,这个有点不同,我不确定为什么会发生这种情况.
在使用标准2011主题的Wordpress 3.4.1安装中出现了这种情况.我使用以下函数将我的脚本排入队列:
function my_scripts(){
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js',null,null,true);
wp_register_script('cycle', 'http://ajax.microsoft.com/ajax/jquery.cycle/2.88/jquery.cycle.all.js',null,null,true);
wp_register_script('plugin', get_stylesheet_directory_uri() . '/scripts/plugin-init.js',null,null,true);
wp_enqueue_script('jquery');
wp_enqueue_script('cycle');
wp_enqueue_script('plugin');
}
Run Code Online (Sandbox Code Playgroud)
首先jquery,cycle脚本都是从CDN中提取出来的.plugin除了cycle对单个元素的基本调用外,该脚本为空.
此时所有浏览器都可以正常工作,但IE9除外.我收到以下错误:
SCRIPT5: Access is denied
jquery.min.js, line 2 character 68522
Run Code Online (Sandbox Code Playgroud)
我很快发现这是一个交叉问题:
SCRIPT5:在xmlhttprequest上的IE9中拒绝访问
我发现这很奇怪,因为我的插件中没有交叉原点功能.问题也出现了,jquery而不是我的代码.尝试了几个建议的修复,但没有运气.
尝试了一些基本的东西.将脚本直接移动到页脚.尝试将其直接移动到标题中.尝试将我的脚本排除在外.此时拔掉我的头发.
我最好的选择是实际看到导致代码错误的原因(因为我无法在缩小版本上).此时代码直接在标题中删除了.min脚本,刷新了,TA-DA:现在一切都顺利进行.
如果我尝试my_scripts()使用wp_register_script&wp_enqueue_script将未分析的脚本声明移回函数,它将再次失败.如果我尝试将未经通知的脚本声明移动到页脚中,它将再次失败.我当时没有测试本地副本,只测试了CDN版本.
这是相同的SCRIPT5错误,但遗憾的是我没有错误产生的代码.前几天这是在办公室,我周末休息.我试图在我的个人沙箱上重现这些事件,但是在重新创建错误方面没有成功,这让我相信一些未列出的内容可能是罪魁祸首.
有谁知道这里发生了什么?为什么jquery.min在未通知的文件不会失败?为什么未通报的文件会继续失败,除非它直接在<head>?
很高兴提供更多信息,虽然有些信息可能要等到我下周回到工作岗位.一旦我能够,我将尝试发布其余的代码.
debugging wordpress jquery internet-explorer internet-explorer-9
我一直在寻找一个简单的例子,说明如何在IE中的跨域请求中发送POST数据(使用XDomainRequest对象).
我已经能够发出简单的POST请求,但无法向其添加POST数据.
任何帮助表示赞赏,谢谢!
我的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) 当我在IE中运行我的网页时,我收到此错误(代码在其他浏览器中运行正常).
这是HTML代码:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
</head>
<body>
<--- some html code --->
<iframe src='http://localhost/page1.php' style="background: transparent; overflow: hidden; height: 210px; width: 390px;" frameborder="0" />
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是page1.php
<!DOCTYPE html>
<html>
<body>
<form action="usercheck.php" method="POST">
USERNAME:<input name="uname" id="uname" type="text" maxlength="12" required/>
<input type="submit" value="Submit">
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是usercheck.php
<?php
//some php code
?>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
</head>
<body>
<--- some html code --->
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
问题是当我usercheck.php点击提交按钮后到达page1.php我得到的错误http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js. Access is …