Don't rely on JQuery's getting started Ajax code

Source: Internet
Author: User

Today I read the example of ajax in head first ajax, which is very good. This book is very good and recommended.

Ajax (Asynchronous Javascript and XML) is Asynchronous Javascript and XML, but Javascript and xml cannot be called Ajax. To put it simply, Ajax is a method for designing and constructing web pages, make it as responsive and interactive as a desktop application. asynchronous means that a browser sends a request like a server without waiting for a response.

To create an Ajax code, take the following steps (this example is created using MVC4 + VS2013 ):

1. Create a View page, that is, an html page.

2. initialize the page

3. Create a request object

4. The server responds to the request code.

5. display on the page

The following describes how to use vs to create an mvc4 empty project.

1. Create a view page

Add Index. cshtml to the view folder and enter the following html code. div is used to display the news list, And button is used to trigger Ajax events.

                
 
 
    window.onload = btn = document.getElementById("btnNews"= 
 
 
=  XMLHttpRequest();=  ActiveXObject("MSxml2:XMLHTTP");=  ActiveXObject("Microsoft:XMLHTTP");= 

 request = newsCount = 0 (document.getElementsByTagName("li") != = document.getElementsByTagName("li" url = "default/GetNews?newsid=" +"GET", url, = displayNews;         request.send(

  GetNews( responseText =  ( i = ; i <= ; i+++= .Format(, i ++= 

 (request.readyState == 4)  (request.status == 200)  divNews = document.getElementById("newsList"+=

 

Next, your support is my motivation!

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.