AjaxʹÓÃʾÀý
/***************************by
garcon1986********************************/
Index.php:
<script type="text/javascript" src="ajax.js" ></script>
<a href="#" onclick="funphp('S')" >S</a>
<a href="for.php?url=E" >E</a>
<div id="idiv"></div>
for.php:
<?php
error_reporting(E_ALL ^ E_NOTICE);
if($url = $_GET[url]){
for($i=1;$i<10;$i++){
echo $url;
}
exit();
}
?>
Ajax.js:
//Ê×ÏÈÉùÃ÷±äÁ¿
var xmlHttp;
//´´½¨¶ÔÏóº¯Êý
function GetXmlHttpObject(){
try{
//Firefox, Opera, Safari
xmlHttp = new XMLHttpRequest();
}
catch(e){
try{
//MS IE 6.0+
xmlHttp = new ActiveXObject(Msxml2.XMLHTTP);
}
catch(e){
try{
//MS IS 5.5+
xmlHttp = new ActiveXObject(Microsoft.XMLHTTP);
}
catch(e){
alert("ÄúµÄä¯ÀÀÆ÷²»Ö§³ÖAJAX£¡");
return false;
}
}
}
}
//·¢ËÍÇëÇóº¯Êý
function funphp(t){
//µ÷ÓÃGetXmlHttpObjectº¯Êý
GetXmlHttpObject();
//open() ·½·¨ÐèÒªÈý¸ö²ÎÊý¡£µÚÒ»¸ö²ÎÊý¶¨Òå·¢ËÍÇëÇóËùʹÓõķ½·¨£¨GET »¹ÊÇ POST£©¡£µÚ¶þ¸ö²ÎÊý¹æ¶¨·þÎñÆ÷¶Ë½Å±¾µÄ
URL¡£µÚÈý¸ö·½·¨¹æ¶¨Ó¦µ±¶ÔÇëÇó½øÐÐÒì²½µØ´¦Àí¡£
xmlHttp.open("GET","for.php?url="+t, true);
//Ö¸¶¨ÏìÓ¦º¯Êý
xmlHttp.onreadystatechange = effect;
//·¢ËÍÇëÇó¡£µ±Ê¹ÓÃGET·½·¨Ê±£¬Ò»°ãsendÀïµÄ²ÎÊýÊÇnull¡£Èç¹ûÊÇPOST»áÓÐËù²»Í¬¡£
xmlHttp.send(null);
}
//´¦Àí·µ»ØÐÅÏ¢º¯Êý
function effect(){
if(xmlHttp.readyState == 4){
if(xmlHttp.status == 200){
var cao = xmlHttp.responseText;
document.getElementById('idiv').innerHTML = cao;
}
}
}
×¢ÊÍ£º
xmlHttpRequest.readyStateµÄ5ÖÖ״̬£º
0 (Uninitialized)
The object has been created, but not initialized (the open method has
not been called).
1 (Open)
The object has been created, but the send method has not been called.
2 (Sent)
The send method has been called. responseText is not available.
responseBody is not available.
3 (Receiving)
Some data has been received. responseText is not available. responseBody
is not available.
Ïà¹ØÎĵµ£º
ÏîÄ¿ÖÐÏëÓÃajax
£¬ÓÚÊÇÔÚÍøÉϰÇÁË
n
¶à×ÊÁÏ£¬·¸ÁË
n
¶à´íÎ󣬴ӽñÌìÉϰൽÏÖÔÚÒ»Ö±ÔÚ´¦ÀíÕâ¸öÎÊÌ⣬ÖÕÓÚ»¹ÊǰÑËü½â¾öÁË¡£
µ±ÎÒ¿´µ½Ò³ÃæµÄajax
ÏÔʾºó£¬ÎÒÐË·ÜÒì³££¬ÎªÁ˼Ǽ×Ô¼ºÑ§Ï°µÄ
ajax
Àú³Ì£¬Ò²ÎªÁËÈøü¶àµÄÈËÉÙ×ßÍä·£¬ÌØÐ´´ËÒ»ÎÄÒÔ¼ÇÖ®£¡
·Ï»°²»ËµÁË£¬ÎªÁ˸üºÃµÄÀí½â£¬ÎÒÖØ×öÁËÒ»¸öСµÄÏî ......
ajax.dllÒѾÊǺÜÀϵĶ«Î÷ÁË£¬µ«ÊǽñÌìÎÒ²ÅÓõ½Ëü£¬ÏÖÔÚ°ÑËüµÄʹÓ÷½·¨¼Ç¼ÏÂÀ´¡£
1.ÔÚweb.configÖÐÅäÖÃajaxµÄ´¦Àí³ÌÐò¡£
<httpHandlers>
<add verb="POST,GET" path="ajax/*.ashx" type="Ajax.PageHandlerFactory, Ajax" />
<httpHandlers>
2. ×¢²á´¦Àí³ÌÐòÀ࣬ajaxTestÊ ......
have been studying parsing JSON from PHP using AJAX to display it in
the client side and jQuery had been a great help to me. Here is a very
simple code in parsing JSON using jQuery that i made.
tablejsondata.php
This file makes the request to a php file and displays the returned data into a tabl ......
ÕâÊÇÒ»¸ö»ùÓÚprototype.jsµÄajax·ÖÒ³£¬ÔËÓÃÁËspring¿ò¼Ü£¬×Ô¶¨Òå·ÖÒ³±êÇ©£¬Ã¿´Î½øÈëÁбíÒ³ÃæÊ±£¬°ÑÁÐ±í´æÈësession£¬·ÖÒ³Ö»¶Ôsession´æ´¢µÄÁÐ±í½øÐзÖÒ³£¬²»ÐèÒªÔÙÈ¥²éѯÊý¾Ý¿â£¬ÐÔÄÜ»á¸ßЩ
Ê×ÏÈÔÚweb.xmlÖÐÅäÖÃspring¼àÌýºÍservlet
web.xmlÄÚÈÝÈçÏ£º
<?xml version="1.0" encoding="UTF-8"?>
<web-app versi ......