Showing posts with label in case it has changed. This mean that I insert the text into the label every 5th second (no matter if it has changed or not). Now the problem is that my xml file get. Show all posts
Showing posts with label in case it has changed. This mean that I insert the text into the label every 5th second (no matter if it has changed or not). Now the problem is that my xml file get. Show all posts

xml file gets deleted unexpectedly on a GET request



I am reading text from a xml file, and insert this text into a Label. I read the text from the xml file every 5th second, in case it has changed. This mean that I insert the text into the label every 5th second (no matter if it has changed or not). Now the problem is that my xml file gets deleted when I do a GET the 2nd time, and this results in a 500 (internal server error), since the file is no longer there.


Here is the code that creates the xml document



[WebMethod]
[ScriptMethod(UseHttpGet=true)]
public string GetMessage() {
XmlTextReader reader = new XmlTextReader (Global.sAppPath + "/alt/importantMsg.xml");

string message = null;

while (reader.Read()) {
if (reader.IsStartElement ()) {
switch (reader.Name.ToString ()) {

case "Message":
message = reader.ReadString();
break;
}
}
}
return message;
}


And here is the code that issues a GET



window.setInterval(function() {
msg;

$.ajax({
url: "http://ift.tt/1rvYRPu",
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
msg = data.d;
},
error: function() {
alert("Error");
}
});

Ext.getCmp('attentionLabel').setText(msg);
Ext.getCmp('attentionLabel').show();

}, 5000);


Below is the code that issues a POST, to save the message to the xml file, along with the client code



[WebMethod]
public void AddToXMLFile (string param)
{
XmlDocument doc = new XmlDocument();
DateTime today = DateTime.Today;

XmlNode rootNode = doc.CreateElement("Scandiatransplant");
XmlNode dateNode = doc.CreateElement("Date");
XmlNode importantMsg = doc.CreateElement("Message");

XmlAttribute msgId = doc.CreateAttribute("id");
msgId.Value = "msgID";

dateNode.InnerText = today.ToString();
importantMsg.InnerText = param;
importantMsg.Attributes.Append(msgId);

rootNode.AppendChild(dateNode);
rootNode.AppendChild(importantMsg);

doc.AppendChild(rootNode);
doc.Save(Global.sAppPath + "/alt/importantMsg.xml");
}


And the client code



function saveMsg(msg) {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST", "http://ift.tt/1rweS84", true); //async
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlhttp.send("param=" + msg);
}


Can anyone see why the xml file suddenly gets deleted, which results in an internal server error?


Read more ...