vinay hegde
vinay hegde

Reputation: 109

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?

Upvotes: 2

Views: 809

Answers (1)

Vishal Rao
Vishal Rao

Reputation: 912

$.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.

Upvotes: 1

Related Questions