Simple Ajax request ASPX page

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.