【问题标题】:Post not working as expected in angularjs发布在angularjs中没有按预期工作
【发布时间】:2015-09-22 00:20:16
【问题描述】:

我正在使用外部 api,它在邮递员中工作得很好,但当我从 angularjs 调用时不起作用。

这是我从 Angular js 调用的方式

$http.post('http://api.quickblox.com/users.json', {
    token: '2ba123a8c43664886c66702fb81b779b094cc7b8',
    'user[email]': email,
    'user[login]': email,
    'user[login]': email,
    'user[password]': password
}).then(function (results) {
    console.log('mid');
});

这是图片预览

效果很好。

但是当我从 angularjs 调用时它不起作用

这是我调用 angularjs 时的响应截图

【问题讨论】:

  • 将角度请求与邮递员的请求进行比较。也许您必须设置额外的标头或 token 无效。
  • token 是有效的,我是附加标题我不确定,所以我尝试查看邮递员的网络,它有一些奇怪的东西..

标签: javascript php angularjs quickblox


【解决方案1】:

看起来您需要提供额外的“Content-Type”标头并重新格式化您发送的数据:

$http.post('http://api.quickblox.com/users.json', {
    token: '2ba123a8c43664886c66702fb81b779b094cc7b8',
    user: {
        email: email,
        login: email,
        password: password
    }
}, {
    'Content-Type': 'application/x-www-form-urlencoded'
})
.then(function(results) {
    console.log('mid');
})
.catch(function(response) {
    console.log('Error', response.status, response.data.errors);
});

演示: http://plnkr.co/edit/ishIqko1GHT7IGvXV8ZF?p=preview

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-14
    • 2014-03-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-25
    • 2014-08-04
    相关资源
    最近更新 更多