Use of the Ajax request $. ajaxsetup Method

Source: Internet
Author: User

You can use jquery's $. ajaxsetup method to set the default parameter options for Ajax requests. WhenProgramWhen you need to initiate multiple Ajax requests, you do not need to configure the request parameters for each request.

$. Ajaxsetup method syntax

$. Ajaxsetup (properties)

Parameters

 

Properties

(Object) an object instance. Its Attributes define a set of default Ajax attributes. These attributes are the same as the $. Ajax function attributes described above.

Return Value

Undefined

Note that the default value set by the $. ajaxsetup function is not applied to the load () command. For utility functions such as $. Get () and $. Post (), the HTTP method is not overwritten by using these default values. Setting the default get type does not cause $. Post () to use the http get method.

Let's look at an example.

ClientCode:

<HTML xmlns = "http://www.w3.org/1999/xhtml"> 

Main server code:

 
Protected void page_load (Object sender, eventargs e) {If (! Page. ispostback) {If (request ["ID"]! = NULL &&! String. isnullorempty (request ["ID"]. tostring () {// enabling the following line of code will cause Ajax request timeout // system. threading. thread. sleep (4000); response. write (getdata (request ["ID"]. tostring () ;}} protected string getdata (string ID) {string STR = string. empty; Switch (ID) {Case "1": Str + = "this is number 1"; break; Case "2": Str + = "this is number 2 "; break; Case "3": Str + = "this is number 3"; break; default: Str + = "Warning Other number! "; Break;} return STR ;}

Run the program and Result

Download demo

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.