得到:$ . GET (. .)
职位:$ . POST () . .
PUT/DELETE呢?
得到:$ . GET (. .)
职位:$ . POST () . .
PUT/DELETE呢?
当前回答
这是一个更新的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
}
});
其他回答
你可以使用ajax方法:
$.ajax({
url: '/script.cgi',
type: 'DELETE',
success: function(result) {
// Do something with the result
}
});
如果你想赚美元。将工作post到Laravel Route::delete或Route::put只需添加一个参数"_method"="delete"或"_method"="put"。
$.post("your/uri/here", {"arg1":"value1",...,"_method":"delete"}, function(data){}); ...
必须适用于其他框架
注:用Laravel 5.6和jQuery 3测试
从这里,你可以这样做:
/* Extend jQuery with functions for PUT and DELETE requests. */
function _ajax_request(url, data, callback, type, method) {
if (jQuery.isFunction(data)) {
callback = data;
data = {};
}
return jQuery.ajax({
type: method,
url: url,
data: data,
success: callback,
dataType: type
});
}
jQuery.extend({
put: function(url, data, callback, type) {
return _ajax_request(url, data, callback, type, 'PUT');
},
delete_: function(url, data, callback, type) {
return _ajax_request(url, data, callback, type, 'DELETE');
}
});
它基本上只是一个复制的$.post()与方法参数调整。
这是一个更新的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
}
});
我写了一个jQuery插件,它包含了这里讨论的跨浏览器支持的解决方案:
https://github.com/adjohnson916/jquery-methodOverride
点击这里查看详情!