I am new to doing Ajax request and have put together the following Pastie. Line 107 is my $.PUT and is throwing an error in firebug that $.PUT does not a function. As for the ajax request I know this is wrong however I am quite lost as to what I need to do inside the success function addCell. Am I going the right way about this?
Edited
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');
}});
The HTTP PUT request method creates a new resource or replaces an existing resource on the server. The Content-Type request header indicates the media type of the PUT request body, and the Content-Length request header indicates the data size in the PUT request message.
AJAX stands for Asynchronous JavaScript And XML. In a nutshell, it is the use of the XMLHttpRequest object to communicate with servers. It can send and receive information in various formats, including JSON, XML, HTML, and text files.
Sends an asynchronous http POST request to load data from the server. Its general form is: jQuery. post( url [, data ] [, success ] [, dataType ] ) url : is the only mandatory parameter.
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() {
}
});
Should be:
function _ajax_request(url, data, callback, method) {
return jQuery.ajax({
url: url,
type: method,
data: data,
success: callback
});
}
and to extend jQuery:
jQuery.extend({
put: function(url, data, callback) {
return _ajax_request(url, data, callback, 'PUT');
}});
and a sample usage example:
$.put('/url', { 'foo': 'bar' }, function(result) {
// do something with the results of the AJAX call
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With