專業鋁門窗、鍛造門設計及安裝
價格便宜、品質好、設計佳,值得您信賴
油漆30多年專業技術團隊
幫您輕鬆搞定房子抓漏防水等惱人問題

首頁  •  j2h 論壇 • 程式設計討論     • 

[JQuery] jQuery Ajax 輕鬆上手!

房東:小強
發表時間:2011-06-12


ajax.html


<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<script src="jquery.js" type="text/javascript" ></script>
<script type="text/javascript" language="javascript">

var i=0;

$(document).ready(initial);

function get_value_for_ajax_POST(){

$.ajax({

type: "POST",

url: "2.php",

data:'name=chihwei',

beforeSend:function(){

$('#res2').html("準備中~~");

},

error:function(xhr,textStatus,errorThrown){

alert("出錯啦!!");

},

success: function(msg){

$('#res2').html(msg);

}

});

}

function get_value_for_ajax_GET(){

$.ajax({

type: "GET",

url: "1.php",

data:'name=chihwei',

beforeSend:function(){

$('#res').html("準備中~~");

},

error:function(xhr,textStatus,errorThrown){

alert("出錯啦!!");

},

success: function(msg){

$('#res').html(msg);

}

});

}

function get_value_for_ajax(){

$.ajax({

url: "3.php",

beforeSend:function(){

$('#res3').html("準備中~~");

},

error:function(xhr,textStatus,errorThrown){

alert("出錯啦!!");

},

success: function(msg){

$('#res3').html(msg);

}

});

}
function initial(){

get_value_for_ajax_POST();

get_value_for_ajax_GET();

get_value_for_ajax();

}

</script>

<title>Ajax</title>

</head>
<body>

<div id="res" ></div>

<div id="res2" ></div>

<div id="res3" ></div>

</body>

</html>



1.php


<?php

echo "Hi你用的是GET,你傳來得值是:".$_GET["name"];

?>



2.php


<?php 

echo "Hi你用的是POST,你傳來得值是:".$_POST["name"];

?>



3.php


<? 

echo "Hi~你是用單純取得頁面資料的方式~~";

?>



如果你有程式底子的話~~



相信看完以上程式碼,



大概就能了解jQuery ajax的運作方式啦~~ :)






  • 贊助網站       

    廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲
    完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心!
    廣利不動產-新板特區指名度最高、值得您信賴的好房仲
    您的托付,廣利用心為您服務



  •  共 0 人回應

    姓名:
    佈告內容:
    其他選項: