Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Ajax PUT with parameters

Tags:

jquery

It seems that using jQuery Ajax POST will pass parameters, but PUT will not. I looked at the current jQuery code and PUT and DELETE are not there. I looked at 1.4.2 jQuery and PUT and DELETE are there.

What is the workaround for passing parameters with a PUT request using the current version of jQuery?

like image 807
andrei g Avatar asked Nov 07 '11 05:11

andrei g


People also ask

What is put in AJAX call?

If you look closely at the URL, we are calling the Put() action; you will find that we are passing the ID using it. Through the ajax() function we are sending the data parameter to the Put() action defined in the person controller. Here is the implementation of the Put() action within the person controller.

Can we send data in AJAX GET request?

In the options parameter, we have specified a type option as a POST, so ajax() method will send http POST request. Also, we have specified data option as a JSON object containing data which will be submitted to the server. So this way you can send GET, POST or PUT request using ajax() method.


1 Answers

Can you provide an example, because put should work fine as well?

Documentation -

The type of request to make ("POST" or "GET"); the default is "GET". Note: Other HTTP request methods, such as PUT and DELETE, can also be used here, but they are not supported by all browsers.

Have the example in fiddle and the form parameters are passed fine (as it is put it will not be appended to url) -

$.ajax({   url: '/echo/html/',   type: 'PUT',   data: "name=John&location=Boston",   success: function(data) {     alert('Load was performed.');   } }); 

Demo tested from jQuery 1.3.2 onwards on Chrome.

like image 144
Jayendra Avatar answered Sep 23 '22 19:09

Jayendra