后未按预期在angularjs [英] Post not working as expected in angularjs
本文介绍了后未按预期在angularjs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是外部API,它工作在邮递员很不错,但不是当我从angularjs调用工作。
I am using an external api, which works very good in postman but not working when i call from angularjs.
这里是我从我的角度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');
});
这里是图像的preVIEW
它的工作原理很好。
但是,它不工作,当我从电话angularjs做
But it is not working when i do from angularjs call
下面是截图当我这样做angularjs调用的响应
Here is screenshot the response when i do angularjs call
推荐答案
看起来你需要提供额外的内容类型标头和重新格式化您要发送的数据:
Looks like you need to provide additional "Content-Type" header and reformat the data you are sending:
$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/编辑/ ishIqko1GHT7IGvXV8ZF?p = preVIEW
这篇关于后未按预期在angularjs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文