Using the Ajax () method to load server data
The use of the ajax() method is the lowest, most powerful method of requesting server data, it can not only get the data returned by the server, but also send a request to the server and pass a numeric value, its invocation format is as follows:
jQuery.ajax([settings])Or$.ajax([settings])
Where the parameter settings is the configuration object when the AJAX request is sent, in which the URL represents the path requested by the server, data is passed at the request, datatype is the data type returned by the server, success is the callback function for the successful execution of the request, Type is the way to send data requests by default to get.
1<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">234<title> load server data using the Ajax () method </title>5<script src= "Http://libs.baidu.com/jquery/1.9.0/jquery.js" type= "Text/javascript" ></script>6<style>7 #divtest8 {9 width:282px;Ten } One #divtest. Title A { - padding:8px; -background-Color:blue; the color: #fff; - height:23px; -line-height:23px; -font-size:15px; +font-Weight:bold; - } + ul A { at float: Left; - width:280px; - padding:5px 0px; - margin:0px; -font-size:14px; -list-style-Type:none; in } - ul Li to { + float: Left; - width:280px; the height:23px; *line-height:23px; $ padding:3px 8px;Panax Notoginseng } - . FL the { + float: Left; A } the . Fr + { - float: Right; $ } $</style> - - the<body> -<div id= "Divtest" >Wuyi<div class= "title" > the<span class= "FL" > detect the parity of numbers </span> -<span class= "FR" > Wu<input id= "btncheck" type= "button" value= "Detect"/> -</span> About</div> $<ul> -<li>request to enter a number -<input id= "Txtnumber" type= "text" size= "/>" -</li> A</ul> +</div> the -<script type= "Text/javascript" > $$(function () { the$ ("#btnCheck"). Bind ("click",function () { the $.ajax ({ theURL: "./8-5.php", theData: {num: $ ("#txtNumber"). Val ()}, -Type: "POST", inSuccessfunction(data) { the$ ("ul"). Append ("<li> you enter <b>" the+ $ ("#txtNumber"). Val () + "</b> Yes <b>" About+ Data + "</b></li>"); the } the }); the }); + }); -</script> the</body>BayiView Code1 <? PHP 2 $num = $_post[' num ']; 3 if ($num%2==0) {4 echo "even"; 5 }else{6 echo "odd"; 7 }
Using the Ajax () method to load server data