我需要在 PUT 方法中发送一个 xhr 请求
这是我的代码:
function put(_url, _callback,_data){
var xhr = createCORSRequest('PUT',_url);
if (!xhr){
throw new Error('CORS not supported');
}
$('.ajax-loading').show();
xhr.send(_data);
/*SUCCESS -- do somenthing with data*/
xhr.onload = function(){
// process the response.
_callback(xhr.responseText);
$('.ajax-loading').hide();
};
xhr.onerror = function(e){
console.log(e);
$('.ajax-loading').show();
};
}
不知道为什么它不起作用,因为它没有将数据传递到我设置的 url。 而在 POST 方法中执行相同的功能是可以的!
有什么想法吗?
最佳答案
您的方法是正确的,可能您需要检查您是否在代码中调用了该函数或其他内容。尝试在控制台中剪切和粘贴函数,然后在控制台中调用它。
在 chrome 中完美运行,即使使用 CORS 服务器也是如此。
告诉我它是否有效。
关于javascript - xhr javascript PUT 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10536032/