【问题标题】:xhr javascript PUT methodxhr javascript PUT 方法
【发布时间】:2012-05-11 05:55:55
【问题描述】:

我需要在 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 方法中执行相同的功能是可以的!

有什么想法吗?

【问题讨论】:

标签: javascript xmlhttprequest put


【解决方案1】:

您的方法是正确的,可能您必须检查您是否在代码中调用了该函数或其他内容。尝试在控制台中剪切和粘贴函数,然后在控制台中调用它。

在 chrome 中完美运行,即使使用 CORS 服务器。

告诉我它是否有效。

【讨论】:

    【解决方案2】:

    PUT 方法不适用于标准浏览器 HTTP 方法。您必须在 POST 变量中创建一个 _method=put 值来模拟 PUT 请求。

    【讨论】:

      猜你喜欢
      • 2015-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-15
      • 2021-06-06
      • 2014-10-29
      • 1970-01-01
      • 2022-02-09
      相关资源
      最近更新 更多