得到:$ . GET (. .)

职位:$ . POST () . .

PUT/DELETE呢?


当前回答

你可以使用ajax方法:

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

其他回答

你可以使用ajax方法:

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

美元。Ajax可以工作。

$.ajax({
   url: 'script.php',
   type: 'PUT',
   success: function(response) {
     //...
   }
});

CRUD

这可能更有道理

创建(POST)请求

function creat() {
  $.ajax({
    type: "POST",
    url: URL,
    contentType: "application/json",
    data: JSON.stringify(DATA1),
    success: function () {
      var msg = "create successful";
      console.log(msg);
      htmlOutput(msg);
    },
  });
}

READ()请求

// GET EACH ELEMENT (UNORDERED)
function read_all() {
  $.ajax({
    type: "GET",
    url: URL,
    success: function (res) {
      console.log("success!");
      console.log(res);
      htmlOutput(res);
    },
  });
}

// GET EACH ELEMENT BY JSON
function read_one() {
  $.ajax({
    type: "GET",
    url: URL,
    success: function (res) {
      $.each(res, function (index, element) {
        console.log("success");
        htmlOutput(element.name);
      });
    },
  });
}

更新(把)请求

function updat() {
  $.ajax({
    type: "PUT",
    url: updateURL,
    contentType: "application/json",
    data: JSON.stringify(DATA2),
    success: function () {
      var msg = "update successful";
      console.log(msg);
      htmlOutput(msg);
    },
  });
}

删除(删除)的请求

function delet() {
  $.ajax({
    type: "DELETE",
    url: deleteURL,
    success: function () {
      var msg = "delete successful";
      console.log(msg);
      htmlOutput(msg);
    },
  });
}

GitHub参考

这是一个更新的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的ajax函数指定

输入:“put”或 类型:“删除”

并不是所有浏览器都支持,而是大多数浏览器都支持。

看看这个问题,了解更多关于兼容性的信息:

PUT, DELETE, HEAD等方法在大多数网络浏览器中可用吗?