2

i need to send an xhr request in PUT method

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!

any ideas?

itsme
  • 47,321
  • 93
  • 214
  • 341

2 Answers2

2

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.

Tell me if it works.

Dario
  • 5,003
  • 1
  • 22
  • 26
-2

PUT methods do not work with standard browser HTTP methods. You will have to create a _method=put value into the POST variables to emulate the PUT request.

matsko
  • 21,377
  • 21
  • 98
  • 140