[英]Create couchdb doc using AngularJs
var post_data ={ "task_list": $scope.task_list,"uri": $scope.uri }
$http({method: 'POST',url: 'http://127.0.0.1:5984/tasklist/'+$scope.task_list, data: post_data})
.success(function(data, status, headers, config) {
console.log("POST SUCCESS")
alert("Successfully added");
})
.error(function(data, status, headers, config) {
console.log("POST ERROR", data)
})
}
} );
When I compile the above code it shows an error of 当我编译上面的代码时,显示错误
127.0.0.1:5984/tasklist/text:1 POST http://127.0.0.1:5984/tasklist/text 400 (Bad Request) admin.html:63 POST ERROR Object {error: "bad_request", reason: "Referer header required."} 127.0.0.1:5984/tasklist/text:1 POST http://127.0.0.1:5984/tasklist/text 400(错误请求)admin.html:63 POST ERROR Object {error:“ bad_request”,原因:“引用标头需要。”}
Why does it show this? 为什么显示呢? Any remedy for this? 有什么补救办法吗?
Hey you need include headers in the post data. 嘿,您需要在发布数据中包含标题。 Since your post url expecting Referer. 由于您的帖子网址需要引荐来源网址。
var post_data = {
method: 'POST',
url: 'http://127.0.0.1:5984/tasklist/'+$scope.task_list,
headers: {
'Content-Type': 'json',
'Referer': 'http://www.example.com/app/index.html' //include headers
},
data: { "task_list": $scope.task_list,"uri": $scope.uri }
}
$http(post_data).success(function(data, status, headers, config) {
console.log("POST SUCCESS")
alert("Successfully added");
})
.error(function(data, status, headers, config) {
console.log("POST ERROR", data)
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.