How to Implement Asynchronous refresh by hand Ajax and asynchronous by hand ajax

Source: Internet
Author: User

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!

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

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.