亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jquery中g(shù)et和post的簡單實(shí)例

 更新時(shí)間:2014年02月04日 09:53:49   作者:  
本篇文章主要是對jquery中g(shù)et和post的簡單實(shí)例進(jìn)行了介紹,需要的朋友可以過來參考下,希望對大家有所幫助

例子:

test.html
頁面引用<script type="text/javascript" src="jquery-1.3.2.min.js"></script>

內(nèi)容有:
<div id="divMsg">Hello World!</div>

用法1:(頁面載入時(shí)讀取遠(yuǎn)程頁面內(nèi)容到divMsg)

$("#divMsg").load(http://localhost:8012/t.php, { "resultType": "html" });

返回類型resultType有如下幾種:

"xml", "html", "script", "json", "jsonp", "text"

用法2:(點(diǎn)擊post數(shù)據(jù)返回?cái)?shù)據(jù))

復(fù)制代碼 代碼如下:

<input type="button" id="bnajax" value="ajax" onclick="ajaxTest()" />
<script type="text/javascript" >
 function ajaxTest()
 {
  $.post("http://localhost:8012/t.php", { "txt": "123" },function(data)

  {
   $("#divMsg").html(data);
  }
  );
 }
</script>


下面是摘自網(wǎng)絡(luò)的函數(shù):

post方法如下:

復(fù)制代碼 代碼如下:

    function test(access_url, tipE){

        $.post(access_url,{ 
            first: "test1", second: "test2"
            }, function(data){
                    if(data.success){
                        $('#' + tipE).html('處理成功');
                    }else{
                        $('#' + tipE).html(data.msg);   
                    }
            },'json'
       )
    }


如果想用get方法,則把post換為get就可以了,挺簡單!

這個(gè)函數(shù)中data值為服務(wù)端返回的值,且為JSON格式,當(dāng)然了,這里可以用其他類型,如text,xml等等之類。

服務(wù)端返回值是JSON格式,如:{success:true, msg:"測試成功"}

相關(guān)文章

最新評論