Sending jquery call to external url

Here is my external api call in angular js

$http.post('http://api.quickblox.com/users.json', {
    token: quickbloxapitoken,
    user: {
        email: email,
        login: firstname,
        password: password
    }
        }, {
            'Content-Type': 'application/x-www-form-urlencoded'
        })
        .then(function(results) {
            var apiid = results.data.user.id;
     }

Here my data is sent to two json arrays, e.g.

enter image description here

And when I try to do the same in jquery, I have my call like this

$.ajax({
    url: 'http://api.quickblox.com/users.json',
    type : 'POST',  
     data: { token: quickbloxapitoken, login: fbname, password: 'fbuserfbuser', email: fbmail},
    success: function(message)
    {
    console.log(message);
    }
    })

Data was sent this way

enter image description here

How can I make my jquery data sent as angularjs?

I mean like that?

enter image description here

+4
source share
1 answer

You need to specify the request contentTypeas application/json.

Also, if you expect JSON in return, you'd better enable dataType(although it probably guessed automatically):

$.ajax({
    url: 'http://api.quickblox.com/users.json',
    type : 'POST',  
    contentType: 'application/json',
    dataType: 'json',
    data: JSON.stringify({
       token: quickbloxapitoken,
       user: {
         login: fbname,
         password: 'fbuserfbuser',
         email: fbmail
       }
    })
});

See Documentation

+3
source

All Articles