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!