PUT Ajax Request

I am new to performing an Ajax request and have compiled the following Pastie . Line 107 is my $ .PUT and throws an error in firebug that $ .PUT is not a function. Regarding the ajax request, I know this is wrong, but I completely lost what I need to do in the addCell success function. Am I right about this?

Edited by

function _ajax_request(url, data, callback, type, method) { return jQuery.ajax({ type: 'PUT', url: "slot_days/show", data: data, success: function(data) { callback($.put('/slot_days/show', { '/slot_days/': 'slot_times' }, function(result) { }); ) } }); } jQuery.extend({ put: function(url, data, callback, type) { return _ajax_request(url, data, callback, type, 'PUT'); }}); 
+7
source share
3 answers

You have an error here (the success function must be anonymous):

 return jQuery.ajax({ type: 'PUT', url: 'slot_days/show', data: data, success: function addCell() { } }); 

Must be:

 function _ajax_request(url, data, callback, method) { return jQuery.ajax({ url: url, type: method, data: data, success: callback }); } 

and for jQuery extension:

 jQuery.extend({ put: function(url, data, callback) { return _ajax_request(url, data, callback, 'PUT'); }}); 

and an example using the example:

 $.put('/url', { 'foo': 'bar' }, function(result) { // do something with the results of the AJAX call }); 
+15
source

It looks like you are not including _ajax_request_PUT.js in your main file. This is why the $.put function cannot be found. Turn it on first, then your error will disappear.

0
source

See a simple and clean answer here: https://stackoverflow.com/a/166268/2168168## Just change the type value to β€œPUT”.

Also handles response 415, which may cause problems for others (it blocked me). Also, the answer is 400 in terms of the data object sent.

0
source

All Articles