jQuery Ajax ʵÀýÑÝʾ
<html>
<head>
<title>jQuery Ajax ʵÀýÑÝʾ</title>
</head>
<script language="javascript" src="../lib/jquery.js"></script>
<script language="javascript">
$(document).ready(function ()
{
$('#send_ajax').click(function (){
var params=$('input').serialize(); //ÐòÁл¯±íµ¥µÄÖµ
$.ajax({
url:'ajax_json.php', //ºǫ́´¦Àí³ÌÐò
type:'post', //Êý¾Ý·¢ËÍ·½Ê½
dataType:'json', //½ÓÊÜÊý¾Ý¸ñʽ
data:params, //Òª´«µÝµÄÊý¾Ý
success:update_page //»Ø´«º¯Êý(ÕâÀïÊǺ¯ÊýÃû)
});
});
//$.post()·½Ê½£º
$('#test_post').click(function (){
$.post(
'ajax_json.php',
{
username:$('#input1').val(),
age:$('#input2').val(),
sex:$('#input3').val(),
job:$('#input4').val()
},
function (data) //»Ø´«º¯Êý
{
var myjson='';
eval('myjson=' + data + ';');
$('#result').html("ÐÕÃû:" + myjson.username + "<br/>¹¤×÷:" + myjson['job']);
}
);
});
//$.get()·½Ê½£º
$('#test_get').click(function ()
{
$.get(
'ajax_json.php',
 
Ïà¹ØÎĵµ£º
ÏÖÔÚÈç¹ûÄãÎʱðÈË“×î½üÁ½ÄêÔÚWeb¿ª·¢ÁìÓò×î»ðµÄ¼¼ÊõÊÇʲô”£¬AjaxÕâ¸ö´ÊÓ¦¸ÃÄÜÕ¼¾Ýһϯ֮µØ¡£È·Êµ£¬×Ô´Ó05Äêµ×±»Ìá³ö£¬Ajax¼¼Êõ¾ÍÒÔÄÑÒÔÏëÏóµÄËÙ¶ÈѸËÙºì±é´ó½Äϱ±£¬Êܵ½ÎÞÊýWeb¿ª·¢ÈËÔ±µÄÇàíùºÍ×·Åõ¡£¶ø¸÷ÖÖÆ½Ì¨ÏµÄAjax¿ò¼Ü¸üÊÇÈçÓêºó´ºËñ°ãÏòÍâð£¬ÒÔÖÁÓÚÁ¬Î¢ÈíÕâÑùÈí¼þÒµµÄ¾ÞÍ·Ò²ÆÈ²»¼°´ýÍÆ³ö×Ô¼ºµÄ¿ò¼Ü&m ......
1£ºAjax¿ÉÒÔͨ¹ýJavaScriptµÄXMLHttpRequest¶ÔÏóÓë·þÎñÆ÷½øÐÐͨÐÅ£¬Í¨¹ýXMLHttpRequest£¬JavaScript¿ÉÒÔÔÚ²»ÖØÔØÒ³ÃæµÄÇé¿öÏÂÓë·þÎñÆ÷½øÐÐͨÐÅ¡£
2£ºXMLHttpRequest ä¯ÀÀÆ÷Ö§³Ö
<script type="text/javascript">
function ajaxFunction()
{
var xmlHttp;
try
{
xmlHtt ......
$.ajax({
type: "post",
url: loginUrl,
data: "username=" +uname + "&password=" +pwd,
async: ......
ÔÚʹÓÃAJAX½øÐгÌÐò¿ª·¢µÄʱºò£¬Ò»Ö±¶¼»áÃæ¶ÔÒ»¸ö»º´æµÄÎÊÌ⣡£¡
¼´ÊÇ£¬ÉÏ´ÎÇëÇóµÄʱºò£¬ÒòΪÄãµÄSQLÓï¾ä»òÕ߯äËûÔÒò£¬webserviceÖзµ»ØÖµÎª¿Õ£¬²»ÊÇÄãÏëÒªµÄ½á¹û¼¯£¬ÔÚÄã·¢ÏÖwebserviceÖÐÓï¾äÌå³ö´íºó£¬½øÐÐÐ޸ģ¬ÖØÐ²âÊÔ£¬ÈÔÈ»ÊÇÉϴεķµ»Ø½á¹û£¡¸Ð¾õ¾ÍÏñÄãµÄÐÞ¸ÄÍêÈ«ÎÞЧ¡£¡£
Æäʵ£¬ÕâÊÇÔÚAJAXµ ......