得到:$ . GET (. .)
职位:$ . POST () . .
PUT/DELETE呢?
得到:$ . GET (. .)
职位:$ . POST () . .
PUT/DELETE呢?
当前回答
简洁:
$.delete = function(url, data, callback, type){
if ( $.isFunction(data) ){
type = type || callback,
callback = data,
data = {}
}
return $.ajax({
url: url,
type: 'DELETE',
success: callback,
data: data,
contentType: type
});
}
其他回答
美元。Ajax可以工作。
$.ajax({
url: 'script.php',
type: 'PUT',
success: function(response) {
//...
}
});
我们可以扩展jQuery来创建PUT和DELETE的快捷方式:
jQuery.each( [ "put", "delete" ], function( i, method ) {
jQuery[ method ] = function( url, data, callback, type ) {
if ( jQuery.isFunction( data ) ) {
type = type || callback;
callback = data;
data = undefined;
}
return jQuery.ajax({
url: url,
type: method,
dataType: type,
data: data,
success: callback
});
};
});
现在你可以使用:
$.put('http://stackoverflow.com/posts/22786755/edit', {text:'new text'}, function(result){
console.log(result);
})
从这里复制
这是一个更新的ajax调用,当你使用JSON与jQuery > 1.9:
$.ajax({
url: '/v1/object/3.json',
method: 'DELETE',
contentType: 'application/json',
success: function(result) {
// handle success
},
error: function(request,msg,error) {
// handle failure
}
});
简洁:
$.delete = function(url, data, callback, type){
if ( $.isFunction(data) ){
type = type || callback,
callback = data,
data = {}
}
return $.ajax({
url: url,
type: 'DELETE',
success: callback,
data: data,
contentType: type
});
}
我写了一个jQuery插件,它包含了这里讨论的跨浏览器支持的解决方案:
https://github.com/adjohnson916/jquery-methodOverride
点击这里查看详情!