简体   繁体   English

发送jquery调用外部URL

[英]sending jquery call to external url

Here's my call to external api in angular js 这是我对角度js的外部api的调用

$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 in two json array like this 这里我的数据以两个json数组发送

在此输入图像描述

And when i try to do the same in jquery i have my call like this 当我尝试在jquery中做同样的事情时,我会像这样打电话

$.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);
    }
    })

The datas was sent like this 数据是这样发送的

在此输入图像描述

How can i make my jquery datas sent like the angularjs one ? 如何使我的jquery数据像angularjs一样发送?

I mean like this ? 我的意思是这样的?

在此输入图像描述

You need to specify the request contentType as application/json . 您需要将请求contentType指定为application/json

Also, if you expect JSON in return, you'd better include the dataType as well (although it's probably automatically guessed): 此外,如果你期望JSON作为回报,你最好还包括dataType (虽然它可能会被自动猜测):

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM