* Generally use JS to monitor button events, should first listen to the page onload event.
Where the *js is written, it will be executed where the page is parsed.
Asynchronous request: The so-called asynchronous request, is to use JS to monitor the button click event, and send the request, wait until the reply, then use JS to page jump, or dynamically change the page.
Use cases: When the request is ashx, you can use the Async method, the page does not need to brush to a blank page of ashx or not for the display of the page.
* Send asynchronous requests using jquery:
$ ("#按钮ID"). Click (Fuction () {
$.get (
"Page Url.ashx",
"a=1&b=2",//can be converted to JSON object here, [id:123,name: "SSS"]
Fuction (data) {
callback function
}
);
});
* Asynchronous use of $.getjson can send request JSON data to the background, the background must send a JSON-compliant string.
* Most complete asynchronous request settings, $.ajax
$.ajax
(
{
URL: "Xxx.ashx",
data:{}
}
)
Learning Note 12JS Asynchronous request