[英]How to insert data in eXist-db by $http in AngularJS through the REST API?
我是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為http:// localhost:9999 / exist / rest / db / data / studentdata.xml,Content-Type為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異常:序言中不允許內容)。
你能告訴我是什么問題嗎? 我該如何解決這個錯誤? 非常感謝你。
現在,我可以使用此代碼運行它了(沒有任何錯誤)。
var promise = $http({
method:'POST',
url: 'http://localhost:9999/exist/rest/db/data/studentdata.xml',
headers: {'Authorization': 'Basic YWRtaW46MTIzNDU2','Content-Type':'application/x-www-form-urlencoded'},
data:'_query=update insert <student><id>3</id><name>three</name></student> into //students'
});
promise.success(function(data){
alert("successful");
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.