得到:$ . GET (. .)
职位:$ . POST () . .
PUT/DELETE呢?
得到:$ . GET (. .)
职位:$ . POST () . .
PUT/DELETE呢?
当前回答
你可以使用ajax方法:
$.ajax({
url: '/script.cgi',
type: 'DELETE',
success: function(result) {
// Do something with the result
}
});
其他回答
似乎可以通过JQuery的ajax函数指定
输入:“put”或 类型:“删除”
并不是所有浏览器都支持,而是大多数浏览器都支持。
看看这个问题,了解更多关于兼容性的信息:
PUT, DELETE, HEAD等方法在大多数网络浏览器中可用吗?
你可以用AJAX来做!
PUT法:
$.ajax({
url: 'path.php',
type: 'PUT',
success: function(data) {
//play with data
}
});
对于DELETE方法:
$.ajax({
url: 'path.php',
type: 'DELETE',
success: function(data) {
//play with data
}
});
我写了一个jQuery插件,它包含了这里讨论的跨浏览器支持的解决方案:
https://github.com/adjohnson916/jquery-methodOverride
点击这里查看详情!
美元。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);
})
从这里复制