fadetoblack
Programmer
The code below is working to a point. At the http_request.readyState statement I get a state of one. How do I complete the process so I can get a state of four and/or another means of getting a value back to the page?
server-side C#
private void Page_Load(object sender, System.EventArgs e){
string[] token=new StreamReader(Request.InputStream).ReadToEnd().Split('^');
ajax_post(token);
}
public void ajax_post(string[] token){
string page=token[1];
XmlDocument doc=new XmlDocument();
doc.Load(@"c:\Inetpub\wwwroot\ajax_post\"+token[0]);
XmlNode answer_node=doc.DocumentElement.SelectSingleNode("page[@id="+page+"]/answers");
answer_node.InnerText=token[3];
doc.Save(@"c:\Inetpub\wwwroot\ajax_post\"+token[0]);
}
client-side javascript
function create_ajax_object(){
if(window.XMLHttpRequest){
http_request=new XMLHttpRequest();
}else if(window.ActiveXObject){
try{
http_request = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
if(!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
}
function save_page(type){
create_ajax_object();
http_request.open('POST',' http_request.send(xml_file+"^"+ current_page +"^next^1~2~3~4");
alert(http_request.readyState);
}
xml file
<?xml version="1.0"?>
<pages>
<page id="1">
<answers></answers>
</page>
<page id="2">
<answers></answers>
</page>
<page id="3">
<answers></answers>
</page>
<page id="4">
<answers></answers>
</page>
<page id="5">
<answers></answers>
</page>
<page id="6">
<answers></answers>
</page>
</pages>
server-side C#
private void Page_Load(object sender, System.EventArgs e){
string[] token=new StreamReader(Request.InputStream).ReadToEnd().Split('^');
ajax_post(token);
}
public void ajax_post(string[] token){
string page=token[1];
XmlDocument doc=new XmlDocument();
doc.Load(@"c:\Inetpub\wwwroot\ajax_post\"+token[0]);
XmlNode answer_node=doc.DocumentElement.SelectSingleNode("page[@id="+page+"]/answers");
answer_node.InnerText=token[3];
doc.Save(@"c:\Inetpub\wwwroot\ajax_post\"+token[0]);
}
client-side javascript
function create_ajax_object(){
if(window.XMLHttpRequest){
http_request=new XMLHttpRequest();
}else if(window.ActiveXObject){
try{
http_request = new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){}
}
}
if(!http_request) {
alert('Cannot create XMLHTTP instance');
return false;
}
}
function save_page(type){
create_ajax_object();
http_request.open('POST',' http_request.send(xml_file+"^"+ current_page +"^next^1~2~3~4");
alert(http_request.readyState);
}
xml file
<?xml version="1.0"?>
<pages>
<page id="1">
<answers></answers>
</page>
<page id="2">
<answers></answers>
</page>
<page id="3">
<answers></answers>
</page>
<page id="4">
<answers></answers>
</page>
<page id="5">
<answers></answers>
</page>
<page id="6">
<answers></answers>
</page>
</pages>