JavaScript version of Ajax send request
(1), create XMLHttpRequest object, this object is the core of Ajax request, is the information carrier of Ajax request and response, the different browser creates different way alone
(2), Request path
(3), using the open method binding to send the request
(4), send the request using the Send () method
(5), get the string Xmlhttprequest.responsetext returned by the server;
(6), obtain the value returned by the server, and store the xmlhttprequest.responsexml in the form of XML object;
(7) The XML Document object is examined and parsed using the Consortium DOM node tree method and properties.
Preface:
Recently, with the implementation of the project on the line, a little bit idle, leisure time to discover the previous written about JavaScript native XMLHTTP Ajax methods and later the jquery plug-in Ajax method, so there are some summary, due to the time reason, not in all browsers to test, Currently tested Ie8,9,10,google Chrome,mozilla Firefox,opera commonly used several, such as everyone in the verification test found that there is a problem, please feedback with me, thank you.
Go straight to the code:
Front-end Code
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
. Ashx Back-end code
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.Script.Serialization;
Using System.Runtime.Serialization.Json;
Using System.IO;
Using System.Text; namespace Webhtml5.handler {///<summary>///ajaxhandlerhelper Summary description///</summary> public class Aja Xhandlerhelper:ihttphandler {public void ProcessRequest (HttpContext context) {context.
Response.ContentType = "Application/json"; Context.
Response.Charset = "Utf-8"; var Ajax_type = context.
request.querystring["Ajax_type"] = = null? Context. request.form["Ajax_type"]: Context.
request.querystring["Ajax_type"]; Switch (ajax_type) {case ' Email ': Context.
Response.Write (Postemail (context));
Break Default:context.
Response.Write ("[{\" age\ ": 28,\" name\ ": \" Zhang Pengfei \ "}]);
Break } public static string Postemail (HttpContext context) {string SemaiL = string.
Empty; if (context. Request.httpmethod = = "Get"} {semail = "[" + Context.
request.querystring["Jsondata"] + "]"; else {semail = "[" + Context.
request.form["Jsondata"] + "]";
return semail;
///<summary>///JSON serialization///</summary> public static string jsonserializer<t> (t)
{DataContractJsonSerializer ser = new DataContractJsonSerializer (typeof (T));
MemoryStream ms = new MemoryStream (); Ser.
WriteObject (MS, T); String jsonstring = Encoding.UTF8.GetString (ms.
ToArray ()); Ms.
Close ();
return jsonstring; ///<summary>///JSON deserialization///</summary> public static T jsondeserialize<t> (String js
onstring) {DataContractJsonSerializer ser = new DataContractJsonSerializer (typeof (T));
MemoryStream ms = new MemoryStream (Encoding.UTF8.GetBytes (jsonstring)); T obj = (t) ser.
ReadObject (MS); return obj;
public bool IsReusable {get {return false; }
}
}
}
Jquery method Extension
The way to jquery is to expand everyone's own Google or Baidu;
Conclusion
Explain the situation: The case appears in the HTML5 Range label value problem, write wrong, we do not care about these, about range label how to take the value of everyone Google or Baidu;