6. Ajax

Source: Internet
Author: User
Tags browser cache

Recommended learning resources from: Zhang Ziqiu http://www.cnblogs.com/zhangziqiu/tag/jQuery%e6%95%99%e7%a8%8b/

Summary:

In jquery, Ajax is used and the flexibility of js to write Ajax is saved. It is also easy to write and read like other Ajax class libraries (ASP Ajax.

Content:

The core function jquery. Ajax (options ). Other functions are simple calls, such as get, post, and load.

Load (URL, [data], [callback]):

Simple and limited. The default get method. The automatic POST method is used when a parameter is set.

1. Ajax interface used to directly return html

2. It is the jquery package set, used in the package set, and loaded to the object

Always pay attention to browser cache. When using get, add the event parameter (newdata (). gettime ()

 

// Send a GET request
                $("#divResult").load("../data/AjaxGetMethod.aspx?param=btnAjaxGet_click" + "&timestamp=" + (new Date()).getTime());
            });
 
            $("#btnAjaxPost").click(function(event)
            {
// Send a POST request
                $("#divResult").load("../data/AjaxGetMethod.aspx", { "param": "btnAjaxPost_click" });
            });
 
            $("#btnAjaxCallBack").click(function(event)
            {
// Send a POST request, and then execute the callback function.
                $("#divResult").load("../data/AjaxGetMethod.aspx", { "param": "btnAjaxCallBack_click" }, function(responseText, textStatus, XMLHttpRequest)
                {
                    responseText = " Add in the CallBack Function! <br/>" + responseText
$ ("# Divresult" ).html (responsetext); // or: Response (this).html (responsetext );
                });
            });
 
            $("#btnAjaxFiltHtml").click(function(event)
            {
// Send a GET request and filter out the "Anshan" item from the result
$ ("# Divresult"). Load ("../data/ajaxgetcityinfo. aspx? Resulttype = html "+" & timestamp = "+ (new date (). gettime () +" Ul> Li: Not (: Contains ('anshan '))");
            });

 

 

Get (URL, [data], [callback], [type]):

Return XMLHttpRequest.

This function sends a GET request. parameters can be directly spliced in URLs, for example:

        $.get("../data/AjaxGetMethod.aspx?param=btnAjaxGet_click");

Or pass the data parameter:

$.get("../data/AjaxGetMethod.aspx", { "param": "btnAjaxGet2_click" });

 

Getjson (URL, [data], [callback]): equivalent to get (URL, [data], [callback], "JSON ")

Getscript (URL, [callback]): equivalent to get (URL, [callback], "script ")

Post (URL, [data], [callback], [type])

Ajax (Option)

 

Ajax functions:

Ajaxsetup (options): no return value. Set the global Ajax default options.

Serilalize (): Return string, sequence string, used for Ajax requests

Serilalizearray (): Return array <Object>, format, return JSON object, non-JSON string

 

Global Ajax events:

In the options parameter attribute in jquery. ajaxsetup (options), there is a global attribute:

Global

Type:Boolean Value

Default Value:True

Note:Whether to trigger a global Ajax event.

There are mainly the following events:

Name

Description

Ajaxcomplete (callback)

Execute the function when the Ajax request is complete.

Ajaxerror (callback)

Execute the function when an error occurs in the Ajax request.

Ajaxsend (callback)

Execute the function before sending an Ajax request

Ajaxstart (callback)

Execute functions at the beginning of an Ajax request

Ajaxstop (callback)

Execute the function at the end of the Ajax request

Ajaxsuccess (callback)

Execute the function when the Ajax request is successful.

Note:

If there are two parameters with the same name in the URL sent by the GET request, for example, two Param parameters:

Http: // localhost/ajaxgetmethod. aspx? Param = multiple & Param = multiple3

Use the server method to obtain the param parameter:

        if (!String.IsNullOrEmpty(HttpContext.Current.Request["Param"]))
        {
            param = HttpContext.Current.Request["Param"];
        }

At this time, the obtained Param is a string that uses "," to separate multiple values:

Multiple,Multiple3

 

 

 

 

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.