繁体   English   中英

xhr javascript PUT方法

[英]xhr javascript PUT method

我需要以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();
  };
}

不知道为什么它不起作用,因为它没有将数据传递给我设置的网址。 同时在POST方法中执行相同的功能就可以了!

有任何想法吗?

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

即使在使用CORS服务器的情况下,Chrome也可以完美运行。

告诉我是否可行。

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

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM