ajaxÓëjQuery·½·¨
ajax.asp
ÏÖÔÚʱ¼äÊÇ< %=Now()%>
ajax.html
<script type="text/javascript">
function Ajax(){
var xmlHttp=null;
if(window.ActiveXObject){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP")
}catch(e){}
}
}else if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
}
if(xmlHttp!=null){
xmlHttp.open("GET","ajax.asp",true);
xmlHttp.onreadystatechange=Call;
xmlHttp.send(null);
}
var p=document.getElementById("content");
function Call(){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
p.innerHTML=xmlHttp.responseText;
}
}
}
}
</script>
<button onclick="Ajax()">»ñÈ¡</button>
ÕâÀïʹÓÃajaxËãÊÇÓÐЩÂé·³ÔÙ¿´¿´Ê¹ÓÃjQuery<script type="text/javascript">
$(function(){
$("button").click(function(){
$("p").load("ajax.asp");
});
});
</script>
$.load()·½·¨
ÉÏÃæʹÓÃÁËloadº¯Êý¡£loadÓï·¨ÈçÏ£¬load(url[,data][,callback])//url:stringÀàÐÍ£¬ÇëÇóHTMLÒ³ÃæµÄURlµØÖ·£»data:ObjectÀàÐÍ£¬·¢Ë͵½·þÎñÆ÷µÄkey/valueÊý¾Ý£»callback£¬FunctionÀàÐÍ£¬ÇëÇóÍê³ÉʱµÄ»Øµ÷º¯ÊýÆäÖÐurl¿ÉʹÓÃÑ¡ÔñÆ÷½ÓÊÕ¸ÃurlÖÐÖ¸¶¨µØÖ·µÄijһԪËØÄÚµÄÎı¾¡£ÕâÊÇÒ»¸öÒ쳣ǿ´óµÄ¹¦ÄÜ£¬¼ÙÈçʹÓô«Í³js·½Ê½µÄ»°¾ÍÐèҪʹÓÃreplaceÈ¥¹ýÂËijЩ×Ö·û£¬»¹¿ÉÄÜÒªÓõ½Regex¡£¶øÏÖÔÚjQueryÖ»Òª¼òµ¥µÄÑ¡ÔñÆ÷¹ýÂ˾ͿÉÒÔÁË¡£$("p").load("ajax.asp h4")£¬ajax.aspÄÚÈÝÈçÏ£º<h4>»ñÈ¡Ö¸¶¨ÄÚÈݵıêÌâ</h4>
<p><%
response.Expires=0
response.Write(now())
%></p>µÚ¶þ¸ö²ÎÊýdata
<script type="text/javascript">
$(function(){
$("button").click(function(){
$("p").load("ajax_data.asp",{name:"wang",age:"23"},func
Ïà¹ØÎĵµ£º
ºìÉ«×ÖÌåΪÖ÷Òª´úÂë
jspÒ³ÃæÖÐ
<script language="javascript">
function updateDB(operate){
var objDom=new ActiveXObject("msxml.DomDocument");
var objRoot=objDom.createElement("All");
objDom.appendChild(objRoot);
var k=document.ge ......
1£ºAjax¿ÉÒÔͨ¹ýJavaScriptµÄXMLHttpRequest¶ÔÏóÓë·þÎñÆ÷½øÐÐͨÐÅ£¬Í¨¹ýXMLHttpRequest£¬JavaScript¿ÉÒÔÔÚ²»ÖØÔØÒ³ÃæµÄÇé¿öÏÂÓë·þÎñÆ÷½øÐÐͨÐÅ¡£
2£ºXMLHttpRequest ä¯ÀÀÆ÷Ö§³Ö
<script type="text/javascript">
function ajaxFunction()
{
var xmlHttp;
try
{
xmlHtt ......
±ÈÈçÒª¸øÓû§±¨¸æÒ»¸ö´íÎó£¬ÓÃÏÂÃæµÄ·½·¨£º
ʹÓÃset_error_handlerÉèÖÃ×Ô¼ºµÄ´íÎó´¦Àíº¯Êý£¬ÔÚ±¨´íµÄµØ·½Ê¹ÓÃtrigger_error£¬ÔÚ×Ô¶¨ÒåµÄ´íÎó´¦Àíº¯ÊýÖиøÓû§ÏÔʾһ¸ö³ö´íÐÅÏ¢Ò³Ãæ¡£
µ«
ÊÇÈç¹ûµ÷ÓÃtrigger_errorµÄÕâ¸öÒ³ÃæÊDZ»Ò»´ÎajaxÇëÇó´¥·¢µÄ£¬ÄÇôajax·µ»Øºó½«µÃµ½Ò»´ó¶ÑÓÃÓÚÏÔʾ´íÎóµÄhtml´úÂë¡£¶øÒ»°ã
ajaxµ÷Óö ......
1£ºAjax¿ÉÒÔͨ¹ýJavaScriptµÄXMLHttpRequest¶ÔÏóÓë·þÎñÆ÷½øÐÐͨÐÅ£¬Í¨¹ýXMLHttpRequest£¬JavaScript¿ÉÒÔÔÚ²»ÖØÔØÒ³ÃæµÄÇé¿öÏÂÓë·þÎñÆ÷½øÐÐͨÐÅ¡£
2£ºXMLHttpRequest ä¯ÀÀÆ÷Ö§³Ö
<script type="text/javascript">
function ajaxFunction()
{
var xmlHttp;
try
{
xmlHtt ......
Ajax½éÉÜ
AJAX - ä¯ÀÀÆ÷Ö§³Ö
AJAX µÄÒªµãÊÇ XMLHttpRequest ¶ÔÏó¡£²»Í¬µÄä¯ÀÀÆ÷´´½¨ XMLHttpRequest ¶ÔÏóµÄ·½·¨ÊÇÓвîÒìµÄ¡£IE ä¯ÀÀÆ÷ʹÓà ActiveXObject£¬¶øÆäËûµÄä¯ÀÀÆ÷ʹÓÃÃûΪ XMLHttpRequest µÄ JavaScript ÄÚ½¨¶ÔÏó¡£ÈçÐèÕë¶Ô²»Í¬µÄä¯ÀÀÆ÷À´´´½¨´Ë¶ÔÏó£¬ÎÒÃÇҪʹÓÃÒ»Ìõ "try and catch" Óï¾ä¡£
<script type="t ......