jQuery, converting from a .POST to .AJAX with a method?
I have the following:
$.post(this.href, { _method: 'delete' }, null, "sc开发者_JS百科ript");
How can I convert that to a:
$.ajax({
type: "POST",
url: ,
data: ,
beforeSend: function() {
},
success: function() {
I'm not use how to deal with URL or how to add the _method: 'delete' where does that go with .ajax?
thanks
The URL is going to remain the same, and the _method:'delete' is going to go into the data section:
$.ajax({
type: "POST",
url: this.href,
data: { _method: 'delete' },
beforeSend: function() {},
success: function() {},
dataType: 'script'
});
documentation of $.post
$.ajax({
type: 'POST',
url: url,
data: data,
success: success
dataType: dataType
});
here's an example of a method i use in my application, note the URL and data parameters will be your this.href and _methods:"delete"
function OnChangeRoom(RoomID) {
$.ajax({
type: "POST",
url: "../server.asmx/GetWordFromRoomID",
data: "{'RoomID':'" + RoomID + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
success: function (data) {
if (data.d.length == 0)
$('#spanWord').html(' ');
else
$('#spanWord').html('Word: ' + data.d);
}
});
}
精彩评论