国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

jQuery封裝的ajax


$.get(url??[,data]??[,fn回呼函數(shù)]???[, dataType]);

  • #data:傳遞給伺服器的數(shù)據(jù),請(qǐng)求字串?、json物件?都可以設(shè)定

  • fn:回呼函數(shù),ajax請(qǐng)求完成後呼叫函數(shù),可以在此函數(shù)完成ajax的後續(xù)處理

  • dataType:伺服器傳回資料類(lèi)型,html、text、xml、json

附註:此ajax是異步的get方式請(qǐng)求


$.post(url[,data][,fn回呼函數(shù)][, dataType]);

  • 該方法與$.get()方法使用完全一致,不同的是其為post方式請(qǐng)求


$.ajax({??//json物件

#url:請(qǐng)求位址,

data:傳遞給伺服器的數(shù)據(jù),

dataType:資料從伺服器傳回格式html、text、xml、json

type:get/post請(qǐng)求方式

success:function(){} ?ajax成功請(qǐng)求後的回呼函數(shù),可以做後續(xù)處理使用

async:[true]異步/false同步,

cache:[true]快取/false不快取,

} )

<!DOCTYPE html>
<html>
    <head>
        <title>php.cn</title>
        <meta charset="utf-8" />
        <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
        <script>
        function f1(){
            //① $.get(url[,data,fn,dataType])
            //$.get('./1.php');
            
            //$.get('./1.php','name=tom&age=20',function(msg){
            //$.get('./1.php',{name:'小強(qiáng)',age:21},function(msg){
            //    alert(msg)
            //});

            $.get('/1.php',{name:'小明',age:21},function(msg){
                alert(msg.name+"--"+msg.age)
            },'json');

            //$.get('./1.php',function(msg){
                //ajax完成請(qǐng)求的“回調(diào)函數(shù)”
                //msg是自定義變量,代表從服務(wù)器返回的信息
            //    alert(msg);
            //});
        }

        function f2(){
            //$.ajax({url: data:  dataType:  type:get/post  success:})
            $.ajax({
                url:'/1.php',
                data:{name:'小方',age:21},
                dataType:'json',
                type:'get',
                success:function(msg){
                    //msg代表服務(wù)器返回的信息
                    alert(msg.name+"--"+msg.age);
                }
            });
        }
        </script>
        <style type="text/css">
        </style>
    </head>
    <body>
        <h2>ajax請(qǐng)求</h2>
        <input type="button" value="請(qǐng)求1" onclick="f1()" />
        <input type="button" value="請(qǐng)求2" onclick="f2()" />
    </body>
</html>
  1. php內(nèi)容為:

<?php
$name=$_GET['name'];
$age=$_GET['age'];
$arr =array(
    'name'=>$name,
    'age'=>$age
    );
echo json_encode($arr);
?>

註:大家可以將這兩個(gè)檔案複製到本地,放在一個(gè)資料夾中進(jìn)行測(cè)試

繼續(xù)學(xué)習(xí)
||
<!DOCTYPE html> <html> <head> <title>php.cn</title> <meta charset="utf-8" /> <script src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> function f1(){ //① $.get(url[,data,fn,dataType]) //$.get('./1.php'); //$.get('./1.php','name=tom&age=20',function(msg){ //$.get('./1.php',{name:'小強(qiáng)',age:21},function(msg){ // alert(msg) //}); $.get('/1.php',{name:'小明',age:21},function(msg){ alert(msg.name+"--"+msg.age) },'json'); //$.get('./1.php',function(msg){ //ajax完成請(qǐng)求的“回調(diào)函數(shù)” //msg是自定義變量,代表從服務(wù)器返回的信息 // alert(msg); //}); } function f2(){ //$.ajax({url: data: dataType: type:get/post success:}) $.ajax({ url:'/1.php', data:{name:'小方',age:21}, dataType:'json', type:'get', success:function(msg){ //msg代表服務(wù)器返回的信息 alert(msg.name+"--"+msg.age); } }); } </script> <style type="text/css"> </style> </head> <body> <h2>ajax請(qǐng)求</h2> <input type="button" value="請(qǐng)求1" onclick="f1()" /> <input type="button" value="請(qǐng)求2" onclick="f2()" /> </body> </html>
提交重置程式碼