如果我创建一个成功的jquery AJAX请求,我会收回我的JSON数据.但是,如果我发出请求并且我得到了200响应代码以外的其他东西,我无法在Jquery回调中获取数据.我需要数据,因为它有关于数据的描述.
success: function (data, tst, xhr) {
$.log('XHR OK');
},
error: function (xhr, tst, err) {
$.log('XHR ERROR ' + XMLHttpRequest.status);
},
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
谢谢
我正在尝试使用AJAX(XMLHttpRequest)向维基百科的API实现一个简单的请求.如果我在Firefox的地址栏中输入网址,我会得到一个整洁的XML,没有汗水.然而,调用完全相同的URL:
// this is my XMLHttpRequest object
httpObjectMain.open("GET", "http://en.wikipedia.org/w/api.php?action=query&format=xml&prop=langlinks&lllimit=500&titles=kaas", true);
httpObjectMain.send(null);
Run Code Online (Sandbox Code Playgroud)
返回一个空响应.根据FireBug,我得到200 OK响应,但内容只是空的.
我怀疑我可能会遗漏GET http请求标题上的内容.
救命!(谢谢!)
在过去,我以为我只是疯了.我可能是,但我的生产日志根本没有响应某些请求.我正在从移动客户端将图像发布到我的rails应用程序,然后在Web浏览器中获取刷新的视图.改变后的记录清晰可见.以上都没有出现在我的生产日志中,但是一小时前就记录了类似的请求.我没有更改任何配置文件.我没有重新启动我的服务器.有关为什么会发生这种情况的任何建议吗?
我只在IE9上遇到此错误:
SCRIPT575:由于错误c00c023f无法完成操作.
错误发生在这一行: if ((a.responseXML) && (a.readyState==4)) {
我无法弄清楚为什么会发生这种情况,而且它似乎在其他浏览器中运行良好.
这是我的javascript代码:
var a = new XMLHttpRequest();
a.open("GET",'/cust/ajax/getresult.php?qk=nnf87&arg1='+pzid,true);
a.onreadystatechange = function () {
if ((a.responseXML) && (a.readyState==4)) {
var N = a.responseXML.getElementsByTagName('result')
sequence = N[0].firstChild.data;
var SEQ = sequence.split(",");
var num = SEQ.length;
var sum = 0;
for(var n=0;n<num;n++){sum = sum + (SEQ[n]*1);}
//document.getElementById("the_number_of").innerHTML = sum;
var date = new Date();
date.setTime(date.getTime()+(2*60*60*1000));
document.cookie='cpa_num='+sum+'; expires= '+date.toGMTString()+'; path=/';
}
}
Run Code Online (Sandbox Code Playgroud) Using Firefox I am trying to download some data from Google Drive using XMLHttpRequest. In the debug console it gives me [302 Moved Temporarily] and the data i receive is empty. How can i get XMLHttpRequest to follow a redirect response? Also I am using https if it changes things.
我通过ajax请求将文件输出到S3,大约50%的时间我收到ERR_CONNECTION_RESET错误.
我知道请求是正确签名的 - 任何想法可能导致这个?同样,这是我从多个位置和机器看到的间歇性问题.
这是我用来将我的文件输出到S3的相关coffeescript代码.它来自Micah Roberson和Rok Krulec在http://micahroberson.com/upload-files-directly-to-s3-w-backbone-on-heroku/和http://codeartists.com/post/36892733572/的工作.如何直接上传文件到亚马逊-s3-from-your.
createCORSRequest: (method, url) ->
xhr = new XMLHttpRequest()
if xhr.withCredentials?
xhr.open method, url, true
else if typeof XDomainRequest != "undefined"
xhr = new XDomainRequest()
xhr.open method, url
else
xhr = null
xhr
uploadToS3: (file, signature) ->
this_s3upload = this
this_s3upload.signature = signature
url = signature.signed_request
xhr = @createCORSRequest 'PUT', decodeURIComponent(signature.signed_request)
if !xhr
@onError 'CORS not supported'
else
xhr.onload = () ->
if xhr.status == 200
this_s3upload.onProgress 100, …Run Code Online (Sandbox Code Playgroud) 使用node.js和浏览器中的Request包(通过browserify),我使用CORS在单独的域上执行HTTP GET请求.
在服务器上,当我设置'Access-Control-Allow-Origin'为通配符时'*',我在客户端上收到以下错误:
的XMLHttpRequest无法加载....通配符"*"不能在使用"访问控制允许来源"标题时,凭证标记为真.因此不允许原点'...'访问.
HTTP请求标头如下所示:
Accept:*/*
Accept-Encoding:gzip,deflate,sdch
Accept-Language:en-US,en;q=0.8,ja;q=0.6
Access-Control-Request-Headers:withcredentials
Access-Control-Request-Method:GET
Cache-Control:no-cache
Connection:keep-alive
Host:localhost:3000
Origin:http://localhost:9966
Pragma:no-cache
Referer:http://localhost:9966/
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36
Run Code Online (Sandbox Code Playgroud)
很明显问题出Access-Control-Request-Headers:withcredentials在标题中,对吗?
为了能够删除它,我需要将'XMLHttpRequest'对象的'withcredentials'属性设置为'false'.但是,我无法弄清楚node.js或Request包在哪里创建'XMLHttpRequest'对象,以及我如何访问它.
谢谢.
我正在尝试为XMLHttpRequest.prototype.open在IE8兼容模式下运行的Intranet站点添加补丁程序,但它一直在投掷SCRIPT438: Object doesn't support this property or method.奇怪的是......如果我"触摸"第arguments一个,即取消注释bar,它就可以正常工作!有谁知道为什么,如果触摸它确实解决了100%的情况下的问题?
var foo = window.XMLHttpRequest.prototype.open;
window.XMLHttpRequest.prototype.open = function() {
//var bar = arguments;
foo.apply(this, arguments);
console.log("OK");
}
Run Code Online (Sandbox Code Playgroud)
这是在IE8模式中的IE9现代.用VM图像搜索的VM截图试图open在滚动时修补猴子的请求.

编辑:
console.log(foo);
//console.log(foo.apply);
console.log(typeof foo);
console.log(foo instanceof Function);
Run Code Online (Sandbox Code Playgroud)
返回
LOG:
function open() {
[native code]
}
LOG: object
LOG: false
Run Code Online (Sandbox Code Playgroud)
在console.log(foo.apply)一个抛出"Object doesn't support this property or method".
有趣的是,我无法在我试过的任何模式下在实际的IE8虚拟机中复制这个,只能在运行IE8标准模式的IE9中.
当我使用该函数将数据添加到数据库时,并且在我添加的服务器上Access-Control-Allow-Origin,它不会被 CORS 阻止,但是当我查看浏览器控制台工具选项卡控制台时仍然出错
Access to XMLHttpRequest at 'https://int.goo.id/api/pg/sso.register' from origin 'http://127.0.0.1:8080' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Run Code Online (Sandbox Code Playgroud)
如何停用 CORS?
我正在使用 Flutter DIO 库。它在我的 Android 应用程序上运行良好,但在 Web 上出现错误。
Error: DioError [DioErrorType.response]: XMLHttpRequest error.
如果我尝试使用 http 相同的 url,它在 Web 上工作正常。我的 Dio 库代码
Dio dio = Dio();
dio.options.method = "POST";
dio.options.headers["Access-Control-Allow-Origin"] = "*";
dio.options.headers["Access-Control-Allow-Credentials"] = true;
dio.options.headers["Access-Control-Allow-Headers"] =
"Origin,Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,locale";
dio.options.headers["Access-Control-Allow-Methods"] =
"GET, HEAD, POST, OPTIONS";
var response = await dio
.post('http://45.79.124.182/app_php/PagarGuru_test/requestAdd.php');
Run Code Online (Sandbox Code Playgroud)
错误日志
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 908:28 get current
packages/dio/src/dio_mixin.dart 819:20 assureDioError
packages/dio/src/dio_mixin.dart 678:13 _dispatchRequest
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 60:31 <fn>
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/zone.dart 1692:54 runBinary
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 175:22 handleError
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 779:46 handleError
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 800:13 _propagateToListeners
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 610:5 [_completeError]
C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/async/future_impl.dart 666:7 …Run Code Online (Sandbox Code Playgroud)