javascript - xhr javascript PUT 方法

标签 javascript xmlhttprequest put

我需要在 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/

相关文章:

javascript - xhr promise 返回错误

javascript - ember vendor js 文件似乎不起作用

javascript - mongoose:如何循环包含对象引用(_id)的数组

javascript - "TypeError: undefined is not an object (evaluating ' _expo.default.Font ')]"异步加载字体时遇到这个错误

node.js - 通过代理使用node-XMLHttpRequest?

javascript - 放置请求获取ID | Axios、React、Redux

javascript - “Redux”未定义...以及 ReactRedux 和 ReactDOM

http - 如何在 HTTP GET 请求中发送原始数据?

c# - WebApi(MVC 5) PUT 方法不允许使用 HTTP/1.1 405 方法

javascript - 如何将获取的数据放入变量中