jquery Access ashx File Sample code _jquery

Source: Internet
Author: User

The. ashx file used to write Web handler. ashx files are similar to. aspx files, which you can use to invoke the HttpHandler class, which eliminates the process of control parsing and page processing for ordinary. aspx pages. is actually a mixed file with HTML and C #.

The. ashx file is suitable for creating data formats for browsers to handle that do not require postback processing, such as for generating dynamic pictures, dynamic text, and so on. Much needs to be used for this type of treatment. This document provides a simple demo that invokes the Ashx file and pastes the source code for the key file.

The following is the source code in the Login.ashx file in demo:

public class Login:ihttphandler {public void ProcessRequest (HttpContext context) {context. 
Response.ContentType = "Application/json"; Get way gets the passed data//string username = context. 
request.querystring["username"]; String Password = context. 

request.querystring["Password"]; Post method gets the passed data string username = context. 
request.form["username"]; String Password = context. 
request.form["Password"]; 
String message = NULL; if (string. 
IsNullOrEmpty (username)) {message = "user name cannot be empty"; Context. Response.Write ("{\" success\ ": False,\" message\ ": \" "+ Message +" \ "}");//This JSON format is very important, otherwise the error function context of jquery will be executed. 
Response.End (); } if (string. 
IsNullOrEmpty (password)) {message = "password cannot be null"; Context. 
Response.Write ("{\" success\ ": False,\" message\ ": \" "+ Message +" \ "}"); Context. 
Response.End (); } if (!string. IsNullOrEmpty (username) &&!string. IsNullOrEmpty (password)) {if (username). 
ToUpper () = = "ADMIN" && password = = "123") {message = "login succeeded"; Context. Response.Write ("{\ "Success\": True,\ "message\": \ "" + Message + "\"} "); 
else {message = "User name or password error"; Context. 
Response.Write ("{\" success\ ": False,\" message\ ": \" "+ Message +" \ "}"); }} context. 

Response.End (); 
public bool IsReusable {get {return false; } 
} 
}

The following is the source code in HTML:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd 
">  

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.