![](/img/trans.png)
[英]How to grab a href value in a simplemodal call and pass the query string along?
[英]how to pass value query string
我如何通过查询字符串发送参数值我的查询字符串 url 是http://ec2-18-222-171-156.us-east-2.compute.amazonaws.com:3002/api/products/delete?id=4但我可以发送通行证。 你能解决我的问题吗?
我的代码:
$(document).on("click", ".products-data .delete", function(e) {
var id = $(this).parent().parent().attr('id');
if (confirm('Delete this product?')) {
$.ajax({
type: 'DELETE',
url: 'http://ec2-18-222-171-156.us-east-2.compute.amazonaws.com:3002/api/products/delete',
dataType: 'json',
data : {id : id},
contentType: 'application/json; charset=utf-8',
success: function(callback) {
console.log("Delete response"+callback);
},
error: function() {
$(this).html("error!");
}
});
}
});
data
参数只会自动附加到GET
请求的 URL 中。 由于您使用的是DELETE
,因此您需要自己进行操作。
url: 'http://ec2-18-222-171-156.us-east-2.compute.amazonaws.com:3002/api/products/delete?id=' + id
在您的success
函数中, callback
是一个对象。 如果要将其与字符串连接,请使用JSON.stringify
。
success: function(callback) {
console.log("Delete response: " + JSON.stringify(callback));
},
使用ajax类型:PUT / POST并传递参数后端功能或检查id值
你好用ajax调用传递数据并用参数调用你的方法
public object delete(int id)
{
//your code
}
$(document).on("click", ".products-data .delete", function(e) {
var id = $(this).parent().parent().attr('id');
if (confirm('Delete this product?')) {
$.ajax({
type: 'DELETE',
url: 'http://ec2-18-222-171-156.us-east-
2.compute.amazonaws.com:3002/api/products/delete',
dataType: 'json',
data : {id : id},
contentType: 'application/json; charset=utf-8',
success: function(callback) {
console.log("Delete response"+callback);
},
error: function() {
$(this).html("error!");
}
});
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.