How to Implement Asynchronous refresh by hand Ajax and asynchronous by hand ajax
The so-called asynchronous refresh means that the entire webpage is not refreshed to update data.
Ajax can be implemented only through js, and asynchronous Refresh can be implemented.
The difference between form submission data and Ajax submission data: Form submission is the data in the entire page submitted, and the previous page will be discarded after data is submitted (refresh the page ); ajax extracts and submits some data on the current page, receives the returned data, and displays the data on the current page after processing (without refreshing the page ).
[Example] = verify whether the user name is repeated =
The idea of using Ajax: Write js and Ajax code on the page to be refreshed, submit the data to another page, write the query code in Page_Load, and return the result to the refreshed page.
Interface
1. Connect to the database using Linq
2. Import the jquery file to the project. Write the code in
<script src="js/jquery-1.2.3.pack.js" type="text/javascript"></script>
3. Write the following code on the refreshed page. Write the code in
<Script src = "js/jquery-1.2.3.pack.js" type = "text/javascript"> </script> <% -- call jquery -- %> <script >$ (document ). ready (// trigger function getval () {$ ("# TextBox1") when the page is ready for loading "). blur (function () {// triggers var txt =$ (this) when the mouse clicks or leaves ). val (); // get the value of the text box. // use ajax to send the value of the text box $. ajax ({url: "De. aspx ", type:" POST ", data: {id: txt}, // receives the information returned by the database datatype:" xml ", success: function (data) {// The data in data is the count data in the De page var co = $ (data ). text (); if (parseInt (co) = 0) {var lbl = document. getElementById ("Label1"); // use js to output lbl. innerHTML = "√";} else {var lbl = document. getElementById ("Label1"); lbl. innerHTML = "this user name has been registered" ;}}}) ;}}); </script>
4. Write the following code in Page_Load on the value passing page:
Protected void Page_Load (object sender, EventArgs e) {// query the passed data DataClassesDataContext dc = new DataClassesDataContext (); string uid = Request ["id"]. toString (); int count = dc. STOpro. where (r => r. stoid = int. parse (uid )). count (); // return Response in xml format. write ("<? Xml varsion = '1. 0'?> "); Response. Write (" <count> "+ count +" </count> "); Response. End (); // turn off Response}
Done!