【发布时间】:2015-12-19 02:43:07
【问题描述】:
我是 AngularJS 的新手。现在我尝试通过 AngularJS 的 REST API 在 eXist-db 数据库中插入 xml 数据。我的文档包含这样的内容:
<students>
<student>
<id>1</id>
<name>one</name>
</student>
<student>
<id>2</id>
<name>two</name>
</student>
</students>
我想在两个学生之后插入一个学生,如下所示:
<students>
<student>
<id>1</id>
<name>one</name>
</student>
<student>
<id>2</id>
<name>two</name>
</student>
<student>
<id>3</id>
<name>three</name>
</student>
</students>
我在 Postman 客户端中使用 POST 请求进行测试,它的工作原理如下图所示: URL is http://localhost:9999/exist/rest/db/data/studentdata.xml, Content-Type is application/x-www-form-urlencoded
之后我尝试像这样在 AngularJS 中使用 $http:
$scope.saveData = function(){
var req={
method:'POST',
url:'http://localhost:9999/exist/rest/db/data/studentdata.xml',
header:{
'Authorization':'Basic YWRtaW46MTIzNDU2',
'Content-Type':'application/x-www-form-urlencoded'
},
data:{_query:'update insert <student><id>3</id><name>three</name></student> into //students'}
};
$http(req).then(function(response){
alert("save finish");
});
}//end function
但它有错误 400(解析请求时出现 SAX 异常:prolog 中不允许内容)。
你能告诉我是什么问题吗?我该如何解决这个错误?非常感谢。
【问题讨论】: