Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ajax/.Net 1.1 readyState problem

Status
Not open for further replies.

fadetoblack

Programmer
Jul 19, 2005
19
US
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>
 
After synchronously invoking http_request.send(), your server side code received the request, does some processing, but never returned any replies via Response, until the event exits. When the control went back to your client, the XmlHttp object flags 1, not 4 (completed), because no data was received.

For more help on this, try posting on the ASP.NET forum.

[wink]
 
I'll try the ASP.Net but everything I tried with Response.OutputStream didn't work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top