0

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!");
                }
            });
        }
    });
1
  • I can't send pass my id value please solve this issue Commented Dec 19, 2019 at 5:55

3 Answers 3

1

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));
},
Sign up to request clarification or add additional context in comments.

2 Comments

i am using above method but can't get response my response is :Delete response[object Object] can you give fiddle example
I've updated the answer to show how to display the response.
0

use ajax type :PUT / POST and pass the parameter backend side function or check the id value

Comments

0

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!");
                }
            });
        }
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.