我的问题是:在 Firefox 中我没有得到任何回应。在 ie 中它工作得很好。
我想要对本地脚本进行 ajax 调用,以纯文本或其他方式获取一些信息。但这行不通。我认为跨脚本此时应该不是问题,或者?
JavaScript 代码很简单:
var targetUrl = "http://localhost/jQueryProxy.php";
var parameters = ""; // later
$.ajax({
type: "GET",
async: true,
url: targetUrl,
data: parameters,
success: function(param1, param2){
alert(param1);
}
});
还有 php 代码:
<?php
header('Content-type: text/xml'));
echo "test";
?>
try var targetUrl = "/jQueryProxy.php";
Also, you can check Firefox's javascript console to look for an error: Ctrl+Shift+J
您还可以尝试通过添加处理程序来查找 jQuery 的 Ajax 错误消息(source) https://stackoverflow.com/questions/377644/jquery-ajax-error-handling-show-custom-exception-messages:
error:function (xhr, ajaxOptions, thrownError){
alert(xhr.status);
alert(xhr.statusText);
alert(thrownError);
}
Update:我做了一些测试,似乎 Firefox 会阻止 Ajax 从本地文件到网络(本地主机也是如此),但不会抛出异常。使用alert($('*', param1).text());
at success
显示当前文档的内容,这很奇怪。
将 XML 作为本地文件放置也不起作用,FF 和 IE 的行为不一致 - 它们的行为非常不同。
最好的选择是将 html 放在服务器 (localhost) 上,与 xml 文件位于同一端口(此处为 80)。
另外,当您的 xml 有效时,请考虑添加dataType:'xml'
.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)