Here we just made a simple string and didn't do XML processing.
<Script language = "JavaScript">
VaR XMLHttpRequest = NULL;
Function selectionchanged ()
{
VaR url = "default. aspx? Index = "+ document. getelementbyid (" select "). value;
// Ie only.
XMLHttpRequest = new activexobject ("msxml2.xmlhttp ");
XMLHttpRequest. onreadystatechange = onreadystatechange;
XMLHttpRequest. Open ("get", URL, true );
XMLHttpRequest. Send (null );
}
Function onreadystatechange ()
{
If (XMLHttpRequest. readystate = 4)
{
If (XMLHttpRequest. Status = 200)
{
VaR wwwww = Document. getelementbyid ("text ");
Wwwww. innerhtml = XMLHttpRequest. responsetext;
}
}
}
</SCRIPT>
I used to make Ajax requests by myself. The ashx page today I requested the ASPX page and found a problem.
<% @ Webhandler Language = "C #" class = "handler" %>
Using system;
Using system. Web;
Using system. Data;
Using system. Web;
Using system. Data. sqlclient;
Public class handler: ihttphandler {
Public void processrequest (httpcontext context ){
Context. response. contenttype = "text/plain ";
Context. response. Write ("Hello World ");
try
{< br> context. response. write (" " + "" + " ");
}< br> catch
{< br> context. response. write ("no record");
}< br> context. response. end ();
}< br>
Public bool isreusable {
get {
return false;
}< BR >}
When it is A. ashx pageContext. response. End (); you do not need to write it, Because processrequest is a complete HTTP request processing,
If you do not enter end, the request ends after the method ends.
When it is A. ASPX page
Public partial class ajax_default: system. Web. UI. Page
{
Protected void page_load (Object sender, eventargs E)
{
Response. contenttype = "text/plain ";
Response. Write ("Hello World ");
Try
{
Response. Write ("<text>" + "" + "</text> ");
}
Catch
{
Response. Write ("no record ");
}
Response. End ();
}
}
Response. End ();It must be written, because pageload is only a part of HTTP request processing, and there is a lot of processing later. If you do not end the returned value, you do not know what to process.