vinay hegde vinay hegde - 5 months ago 33
Ajax Question

Converting CURL to AJAX request

I need to convert the below CURL request to AJAX,

CURL : $ curl -X POST http://textbelt.com/text -d number=5551234567 -d "message=I sent this message for free with textbelt.com"


The AJAX request that I've written is below:

$.ajax({
type: 'post',
url: "http://textbelt.com/text",
data: "number=+1********** message='This is a test message!",

success:function(response)
{
console.log("Success!!");
},

error : function(xhr, status, error)
{
console.log("Status of error message" + status + "Error is" + error);
}

});


The response I get from the server is:

{
"success": false,
"message": "Number and message parameters are required."
}


Can anyone please guide me in the right direction?

Answer
$.ajax({
type: 'post',
url: "http://textbelt.com/text",        
data: {"number":"+1**********", "message":"This is a test message!"},           

success:function(response)
{
    console.log("Success!!");
},

error : function(xhr, status, error)
{
    console.log("Status of error message" + status + "Error is" + error);
}   

});

The above should work.

Comments