使用 AngularJs 创建 couchdb 文档


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

当我编译上面的代码时,它显示的错误

127.0.0.1:5984/任务列表/文本:1 POST http://127.0.0.1:5984/tasklist/text 400(错误请求) admin.html:63 发布错误对象 {错误:"bad_request",原因:"需要引用标头。

为什么显示这一点?对此有什么补救措施吗?

嘿,

您需要在帖子数据中包含标题。由于您的帖子网址期待引用者。

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

最新更新