欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery中get和post的簡單實例

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

例子:

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

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

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

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

返回類型resultType有如下幾種:

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

用法2:(點擊post數(shù)據(jù)返回數(shù)據(jù))

復制代碼 代碼如下:

<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)絡的函數(shù):

post方法如下:

復制代碼 代碼如下:

    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就可以了,挺簡單!

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

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

相關文章

最新評論