简体   繁体   English

xhr javascript PUT方法

[英]xhr javascript PUT method

i need to send an xhr request in PUT method 我需要以PUT方法发送xhr请求

this is my code : 这是我的代码:

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();
  };
}

don't know why it doesn't works cause it doesn't pass data to the url i set. 不知道为什么它不起作用,因为它没有将数据传递给我设置的网址。 while doing same function in POST method is ok! 同时在POST方法中执行相同的功能就可以了!

any ideas? 有任何想法吗?

Your method is correct, probably you have to check if you call that function in the code or something else. 您的方法是正确的,可能您必须检查是否在代码中或其他地方调用了该函数。 Try to cut & paste the function in console, then call it in the console. 尝试在控制台中剪切并粘贴该函数,然后在控制台中调用它。

In chrome works perfectly, even with a CORS server. 即使在使用CORS服务器的情况下,Chrome也可以完美运行。

Tell me if it works. 告诉我是否可行。

PUT methods do not work with standard browser HTTP methods. PUT方法不适用于标准浏览器HTTP方法。 You will have to create a _method=put value into the POST variables to emulate the PUT request. 您将必须在POST变量中创建一个_method = put值来模拟PUT请求。

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

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