得到:$ . 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
});
}
其他回答
简洁:
$.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来做!
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。ajax:
使用HTTP加载远程页面 请求。
你可以通过type选项指定应该使用哪个方法:
要发出的请求类型(“POST”或 "GET"),默认为"GET"。注:其他 HTTP请求方法,如PUT和 DELETE也可以用在这里,但是 他们并没有得到所有人的支持 浏览器。
阿贾克斯()
寻找参数类型
这里也可以使用其他HTTP请求方法,如PUT和DELETE,但并非所有浏览器都支持它们。
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参考