jquery ajax 運用
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>jquery ajax運用</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-store"> <meta http-equiv="expires" content="0"> <meta http-equiv="Content-Type" content="text/html;charset=GBK"> <script type="text/javascript" src="./jquery-1.3.2.min.js"></script> </head><script language="JavaScript">$("#ajax_test").click(function(){ $.ajax({ url:"localhost:8080/demo/test.do?method=getName", type:"post", data:"name=ZXCVB", timeout:15000,//逾時時間 beforeSend:function(XMLHttpRequest){ //alert('遠程調用開始...'); $("#loading").html("<img src='/jqueryStu/images/loading.gif' />"); }, success:function(data,textStatus){ alert('開始回調,狀態文本值:'+textStatus+' 返回資料:'+data); //開始遍曆data的值 for(var i=0;i<data.length;i++){ } }, complete:function(XMLHttpRequest,textStatus){ // alert('遠程調用成功,狀態文本值:'+textStatus); $("#loading").empty(); }, error:function(XMLHttpRequest,textStatus,errorThrown){ alert('error...狀態文本值:'+textStatus+" 異常資訊:"+errorThrown); $("#loading").empty(); } });});</script> <body><input type="button" id="ajax_test2" value="Ajax方式"><div id="loading"></div> </body></html>