Reload xml file data after updating

17 views
Skip to first unread message

Thế Bảo Đinh

unread,
Aug 27, 2015, 10:57:30 AM8/27/15
to AngularJS
Hi , i am using php + angularjs . I have 2 functions :

function loadComment(){
services.getComments().then(function(data){
var source = x2js.xml_str2json(data.data);
var comments = ($filter('filter')(source.data.comment, {itemID: shopItemID }));
$scope.comments = comments;
});
};
$scope.addComment = function()
{
var request = $http({
method: "post",
url: "xmlAction.php",
data: {
id:shopItemID,
functionname: 'addNewComment',
description: 'Description Comment',
name:'Alex'
},
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
});
loadComment();
};

After running add new comment function , xml file is already update, but the function loadComment is still using old data from cache. How can i solve it ?
Thanks.

Sander Elias

unread,
Aug 27, 2015, 11:13:20 AM8/27/15
to AngularJS
Hi Thé

Reload the xml file, or manual push the added comment to your result set in memory.

Regards
Sander

Thế Bảo Đinh

unread,
Aug 27, 2015, 1:10:14 PM8/27/15
to AngularJS
Yes, in loadcomment function . i already use:
app.factory("services", ['$http', function($http) {
var serviceBase = 'services/'
var obj = {};
obj.getComments = function(){
return $http.get("data/comment.xml");
}

function loadComment(){
services.getComments().then(function(data){
var source = x2js.xml_str2json(data.data);
var comments = ($filter('filter')(source.data.comment, {itemID: shopItemID }));
$scope.comments = comments;
});
};

But it can not re load.

Sander Elias

unread,
Aug 28, 2015, 1:39:25 AM8/28/15
to AngularJS
Hi Thé,

Then your server has not commit the changes yet. Then you don't need to reload, but update your result manually (typically, push the extra comment into the array.

Regards
Sander

Bao

unread,
Aug 28, 2015, 1:45:06 AM8/28/15
to ang...@googlegroups.com
But some cases it is more complicated to do than reload directly from XML file. No way to reload XML file in server.

From: Sander Elias
Sent: ‎8/‎28/‎2015 1:39 AM
To: AngularJS
Subject: [AngularJS] Re: Reload xml file data after updating

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/sAE0KZZFrBg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Sander Elias

unread,
Aug 28, 2015, 2:06:33 AM8/28/15
to AngularJS
Hi Thé,

Then a crude solution could be to put in a timeout before the reloading. Give your server some time to commit the change. Keep in mind that this is a very dirty solution, and it will occasionally fail. Best thing is to make sure the server returns the updated results. 

Regards
Sander

Thế Bảo Đinh

unread,
Aug 28, 2015, 11:43:51 AM8/28/15
to ang...@googlegroups.com
So i have one thing can not understand . When the first time , i click button add comment, the xml file already adds new item, but the server still keeps the old file . It is ok, but when i click button add comment again, the server can update the xml file. I don't know why only the first time it can not update.

Bao Dinh 
Web developer

--
Reply all
Reply to author
Forward
0 new messages