Reputation: 51
How do i send parameter value via querystring my query string url is http://ec2-18-222-171-156.us-east-2.compute.amazonaws.com:3002/api/products/delete?id=4 but i could send pass. could you please resolve my issues.
My 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!");
}
});
}
});
Upvotes: 0
Views: 46
Reputation: 101
hello pass data with ajax call and call your method with parameters
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!");
}
});
}
});
Upvotes: 0
Reputation: 780673
The data
parameter is only appended to the URL automatically for GET
requests. Since you're using DELETE
, you need to do it yourself.
url: 'http://ec2-18-222-171-156.us-east-2.compute.amazonaws.com:3002/api/products/delete?id=' + id
In your success
function, callback
is an object. If you want to concatenate it with a string, use JSON.stringify
.
success: function(callback) {
console.log("Delete response: " + JSON.stringify(callback));
},
Upvotes: 1
Reputation: 44
use ajax type :PUT / POST and pass the parameter backend side function or check the id value
Upvotes: 0