得到:$ . GET (. .)

职位:$ . POST () . .

PUT/DELETE呢?


当前回答

你可以使用ajax方法:

$.ajax({
    url: '/script.cgi',
    type: 'DELETE',
    success: function(result) {
        // Do something with the result
    }
});

其他回答

阿贾克斯()

寻找参数类型

这里也可以使用其他HTTP请求方法,如PUT和DELETE,但并非所有浏览器都支持它们。

你可以使用ajax方法:

$.ajax({
    url: '/script.cgi',
    type: 'DELETE',
    success: function(result) {
        // Do something with the result
    }
});

你应该会使用jQuery。ajax:

使用HTTP加载远程页面 请求。

你可以通过type选项指定应该使用哪个方法:

要发出的请求类型(“POST”或 "GET"),默认为"GET"。注:其他 HTTP请求方法,如PUT和 DELETE也可以用在这里,但是 他们并没有得到所有人的支持 浏览器。

你可以在你的数据散列中包含一个名为:_method的键,值为'delete'。

例如:

data = { id: 1, _method: 'delete' };
url = '/products'
request = $.post(url, data);
request.done(function(res){
  alert('Yupi Yei. Your product has been deleted')
});

这也适用于

我写了一个jQuery插件,它包含了这里讨论的跨浏览器支持的解决方案:

https://github.com/adjohnson916/jquery-methodOverride

点击这里查看详情!