AJAXʵÀý£º¸ù¾ÝÓʱà×Ô¶¯Íê³ÉµØÖ·ÐÅÏ¢_Ajax±à³Ì_ºÚ¿Í·ÀÏßÍø°²·þÎñÆ÷ά»¤»ùµØ--Powered by WWW.RONGSEN.COM.CN

AJAXʵÀý£º¸ù¾ÝÓʱà×Ô¶¯Íê³ÉµØÖ·ÐÅÏ¢

×÷ÕߣººÚ¿Í·ÀÏßÍø°²Ajax½Ì³Ì»ùµØ À´Ô´£ººÚ¿Í·ÀÏßÍø°²Ajax½Ì³Ì»ùµØ ä¯ÀÀ´ÎÊý£º0

±¾Æª¹Ø¼ü´Ê£ºÍê³ÉµØÖ·ÐÅÏ¢×Ô¶¯
ºÚ¿Í·ÀÏßÍø°²ÍøѶ£º¡¡¡¡²ÉÓÃÒ»¸ö¿ªÔ´µÄAJAX¿â£ºAjax Toybox ¡¡¡¡ÃèÊö£º¡¡¡¡ÔÚ×¢²á»ò¹ºÎï³µ½áÕʵÄʱºò£¬ÐèÒªÓû§ÌîÈë¸öÈË×ÊÁÏ£¬Õâ¸ö»·½Ú¿ÉÒÔ¼òÁ·Ò»Ï£¬ÎÒÃÇÖ»Ðè¿ÍÈËÌîÈëÓÊÕþ±àÂ룬Ȼºó¾Í¸ù¾ÝÕâ¸öÓÊÕþ±àÂ룬×Ô¶¯...

¡¡¡¡²ÉÓÃÒ»¸ö¿ªÔ´µÄAJAX¿â£ºAjax Toybox

¡¡¡¡ÃèÊö£º

¡¡¡¡ÔÚ×¢²á»ò¹ºÎï³µ½áÕʵÄʱºò£¬ÐèÒªÓû§ÌîÈë¸öÈË×ÊÁÏ£¬Õâ¸ö»·½Ú¿ÉÒÔ¼òÁ·Ò»Ï£¬ÎÒÃÇÖ»Ðè¿ÍÈËÌîÈëÓÊÕþ±àÂ룬Ȼºó¾Í¸ù¾ÝÕâ¸öÓÊÕþ±àÂ룬×Ô¶¯´ÓÊý¾Ý¿âÖÐÈ¡³öÏàÓ¦µÄÊ¡£¬ÊеȵØÖ·ÐÅÏ¢¡£ÕâÑù¼È¿ÉÒÔ¼õÉÙ¿Í»§µÄÊäÈ룬Ôö¼Ó¿Í»§ÌåÑ飬ÓÖ¿ÉÒÔ¼õÉÙÓÉÓÚ×ÊÁÏÊäÈë¶ø²úÉúµÄ´íÎó¡£

¡¡¡¡ÊµÏÖ£º

HTML
<script>
function createRequestObject() {
var ro;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
ro = new ActiveXObject("Microsoft.XMLHTTP");
}else{
ro = new XMLHttpRequest();
}
return ro;
}

var http = createRequestObject();

function sndReq(zip) {
http.open('get', 'zipcode.php?zip='+zip);
http.onreadystatechange = handleResponse;
http.send(null);
}

function handleResponse() {
if(http.readyState == 4){
var response = http.responseText;
var update = new Array();

if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById("city").value = update[0];
document.getElementById("state").value = update[1];
}
}
}
</script>
<h3>Enter A United States Zipcode, Then Tab</h3>
<table align="center">
<tr>
<td>Enter Zipcode:</td>
<td><input type="text" id="zipcode" name="zipcode" onBlur="sndReq(this.value);"/></td>
</tr>
<tr>
<td>City:</td>
<td><input type="text" id="city" name="city"/></td>
</tr>
<tr>
<td>State:</td>
<td><input type="text" id="state" name="state"/></td>
</tr>
</table>

¡¡¡¡ÒÔÉÏÊÇ¿Í»§ÊäÈëÒ³Ã棬ÏÂÃæÊÇ·þÎñ¶ËµÄ´¦ÀíÒ³Ãæ'zipcode.php

<?php
dbuser = 'root';
dbpass = '111111';

cn = mysql_connect("localhost", dbuser, dbpass);
db = mysql_select_db("ajax");

sql = "select city, state from zipcodes where zipcode = " . _REQUEST['zip'];
rs = mysql_query(sql);
row = mysql_fetch_array(rs);

echo row['city'] . "|" . row['state'];

mysql_close(cn);
?>

¡¡¡¡µ±¿Í»§ÊäÈëÒ»¸öPOSTCODEºó£¬zipcode.php¾Í½ÓÊÕµ½Ëü£¬È»ºó½øÐдÓÊý¾Ý±íÖÐÈ¡³ö¶ÔÓ¦µÄ×ÊÁÏ£¬ÔÙ°´Ò»¶¨µÄ¸ñʽ·µ»Ø¸ø¿Í»§¶Ë£¨´Ë´¦ÊÇÒÔ | ·Ö¸ô£©¡£×îºó¿Í»§¶Ë½ÓÊÕ·µ»ØµÄ×ÊÁÏ£¬ÏÔʾÔÚÒ³ÃæÉÏ¡£

if(response.indexOf('|' != -1)) {
update = response.split('|');
document.getElementById("city").value = update[0];
document.getElementById("state").value = update[1];
}

    ºÚ¿Í·ÀÏßÍø°²·þÎñÆ÷ά»¤·½°¸±¾ÆªÁ¬½Ó£ºhttp://www.rongsen.com.cn/show-15875-1.html
Íøվά»¤½Ì³Ì¸üÐÂʱ¼ä:2012-04-05 00:08:31  ¡¾´òÓ¡´ËÒ³¡¿  ¡¾¹Ø±Õ¡¿
ÎÒÒªÉêÇë±¾Õ¾£ºNµã | ºÚ¿Í·ÀÏß¹ÙÍø |  
רҵ·þÎñÆ÷ά»¤¼°Íøվά»¤ÊÖ¹¤°²È«´î½¨»·¾³£¬ÍøÕ¾°²È«¼Ó¹Ì·þÎñ¡£ºÚ¿Í·ÀÏßÍø°²·þÎñÆ÷ά»¤»ùµØÕÐÉ̽øÐÐÖУ¡QQ:29769479

footer  footer  footer  footer