我正在开发示例应用程序来学习angularjs
using node.js
。当我将数据发布到后端以创建新的family
我收到错误如下:
Error: $http:badreq
Bad Request Configuration
Http request configuration url must be a string. Received:
{
"method":"POST",
"url":"api/family",
"data": {
"username":"fagruddin",
"password":"valaanur",
"familyLeader":"fagruddin",
"husband":"fagruddin",
"wife":"rejiya",
"child":2
},
"headers":{
"Content-Type":"application/x-www-form-urlencoded"
}
}
这里出了什么问题?有人帮我解决这个问题吗?
现场演示供您参考 https://ide.c9.io/a3gwebtrain/myfamily
如果您使用快捷方式 post 方法,则省略配置参数,使第一个参数成为 url。
由于您传入配置对象而不是 url 作为第一个参数,因此您会收到错误。
$http.post(
'/api/family',
vm.form,
{headers: {'Content-Type': 'application/x-www-formurlencoded'}}
).success(function(data) {
console.log( 'data', data );
})
如果您使用直接http,那么您可以传递配置对象:
$http({
method: 'POST',
url: 'api/family',
data : vm.form,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(data) {
console.log( 'data', data );
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)