简体   繁体   English

XMLHttpRequest的open()在Chrome中失败

[英]XMLHttpRequest's open() fails in Chrome

I am trying to patch up a bit of AJAX that doesn't work in Chrome. 我正在尝试修补一些在Chrome中无法使用的AJAX。 It's not my script and I'd rather not convert the whole thing to jQuery. 这不是我的脚本,我不想将整个内容转换为jQuery。

xmlhttp.open("GET", query, true);
xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState == 4) {
        console.log(xmlhttp.responseText);
    }
}
xmlhttp.send();

This actually outputs something in the log while using Internet Explorer, but when in (Ch)rome I get an empty string, since the JS debugger tells me that GET failed. 使用Internet Explorer时,这实际上会在日志中输出某些内容,但是在(Ch)rome中时,我会得到一个空字符串,因为JS调试器告诉我GET失败。 The target URL is correct since it works in IE, but it is some kind of ASP.NET script which inner workings I'm not very familiar with (I do the HTML, CSS and JavaScript around here). 目标URL是正确的,因为它可以在IE中使用,但是它是某种ASP.NET脚本,其内部工作方式我并不十分熟悉(我在此处使用HTML,CSS和JavaScript)。

Why could it be that IE is allowed to retrieve the information from the target, but not Chrome? 为什么会允许IE从目标而不是Chrome检索信息? When using Chrome xmlhttp is a XMLHttpRequest and IE gets some kind of ActiveXObject . 当使用Chrome时, xmlhttpXMLHttpRequest而IE获取某种ActiveXObject

Edit. 编辑。 I found some possible solutions here . 我在这里找到了一些可能的解决方案。 Response.Close() , no async or specified/empty data type. Response.Close() ,没有异步或指定/空的数据类型。 It's jQuery though. 不过是jQuery。

Edit #2. 编辑#2。 What Chrome is saying about my headers. Chrome在谈论我的标题。

Can you view the url by typing it into the address bar in Chrome? 您可以通过在Chrome浏览器的地址栏中输入网址来查看该网址吗? There could just be something about your browser config that prevents Chrome from seeing the server. 您的浏览器配置可能会阻止Chrome浏览器查看服务器。

Another possibility is that you are being scuppered by the Same Origin Policy - is the url you are accessing on the same domain as the page? 另一种可能性是您被相同来源策略所困扰-您所访问的URL与页面在同一域中吗?

Okay, so I've solved it. 好的,我已经解决了。 Chrome apparently dislikes having Response.Close() at the end of the requested page. Chrome显然不喜欢在请求的页面末尾添加Response.Close() Changing to Response.End() fixed it. 更改为Response.End()修复了该问题。 Thank you for your help! 谢谢您的帮助!

I also replaced that JavaScript with one line of jQuery. 我还用一行jQuery替换了JavaScript。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 XMLHttpRequest()。Open不是firefox中的函数,但适用于chrome - XMLHttpRequest().Open is not a function in firefox but works in chrome 在新窗口中打开XMLHttpRequest的responseText - Open XMLHttpRequest's responseText in new window XMLHttpRequest打开函数的异步事件监听器 - XMLHttpRequest open function's async event listener Google Chrome无法在连接关闭时加载XMLHttpRequest响应 - Google Chrome fails to load XMLHttpRequest response on Connection close 到 Amazon S3 的 XMLHttpRequest 仅在某些计算机上失败 - XMLHttpRequest to Amazon S3 fails only on some computers 我应该如何解决 Chrome 的 XMLHttpRequest 侵入性“加载”行为? - How should I solve Chrome's XMLHttpRequest intrusive 'loading' behavior? Chrome的加载指示器在XMLHttpRequest期间保持旋转 - Chrome's loading indicator keeps spinning during XMLHttpRequest 使用XMLHttpRequest的open()函数循环访问某些URL - loop through some urls using XMLHttpRequest's open() function 带有XMLHttpRequest的open方法的javascript:使用post及其参数 - javascript with XMLHttpRequest's open method: using post and its parameters JavaScript XMLHttpRequest发送失败 - JavaScript XMLHttpRequest send fails
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM