jquery uses the Ajax () method to load server data

Source: Internet
Author: User

Use ajaxSetup() the method to set some of the global option values for the AJAX request, and after the setup is complete, the subsequent AJAX requests will not need to add these option values, which are called in the following format:

jQuery.ajaxSetup([options])Or$.ajaxSetup([options])

The optional options parameter is an object that sets the global option value for an AJAX request.

For example, first call the ajaxSetup() method to set the global Ajax option value, then click two buttons, respectively, using the ajax() method to request different server data, and display the data content on the page, as shown in:

Effects displayed in the browser:

As you can see, when you use ajaxSetup() the method to set some of the global configuration options for AJAX requests, you only need to set the URL address when you call the AJAX Request Server TXT file two times.

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Use the Ajaxsetup () method to set global AJAX request default options </title>
<script src= "Http://libs.baidu.com/jquery/1.9.0/jquery.js" type= "Text/javascript" ></script>
<link href= "Style.css" rel= "stylesheet" type= "Text/css"/>

<body>
<div id= "Divtest" >
<div class= "title" >
<span class= "FL" > Parity and is greater than 0</span>
<span class= "FR" >
<input id= "btnshow_1" type= "button" value= "Verify 1"/>
<input id= "btnshow_2" type= "button" value= "Verify 2"/>
</span>
</div>
<ul>
<li> Request input A number
<input id= "Txtnumber" type= "text" size= "/>"
</li>
</ul>
</div>

<script type= "Text/javascript" >
$ (function () {
$.ajaxsetup ({
Type: "Post",
Success:function (data) {
$ ("ul"). Append ("<li> you enter <b>"
+ $ ("#txtNumber"). Val () + "</b> Yes <b>"
+ Data + "</b></li>");
}
});
$ ("#btnShow_1"). Bind ("click", Function () {
$.ajax ({
Data: {num: $ ("#txtNumber"). Val ()},
URL: "http://www.imooc.com/data/check.php"
});
})
$ ("#btnShow_2"). Bind ("click", Function () {
$.ajax ({
Data: {num: $ ("#txtNumber"). Val ()},
URL: "http://www.imooc.com/data/check_f.php"
});
})
});
</script>
</body>

jquery uses the Ajax () method to load server data

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.