下面就通过get方法传递参数到php页面为例来说一下:
test.html
test.js
var xmlhttp;function getxmlhttpobject(){ if (window.xmlhttprequest){ // code for ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); }else{// code for ie6, ie5 xmlhttp=new activexobject(microsoft.xmlhttp); } return xmlhttp;}// -----------ajax方法-----------//function testcheck(){ xmlhttp=getxmlhttpobject(); if (xmlhttp==null){ alert('您的浏览器不支持ajax!'); return; } var url=http://localhost/phptest/index.php?isbn=110120;//这个地方一定要注意哦,刚开始的时候我在‘=’前面多了一个空格,结果造成了php页面获取不到参数,大家都一定要注意些哦 xmlhttp.open(get,url,true); xmlhttp.onreadystatechange=getokget;//发送事件后,收到信息了调用函数 xmlhttp.send();}function getokget(){ if(xmlhttp.readystate==1||xmlhttp.readystate==2||xmlhttp.readystate==3){ // 本地提示:加载中 } if (xmlhttp.readystate==4 && xmlhttp.status==200){ alert(xmlhttp.responsetext); alert('123'); // 处理返回结果 }}
index.php
另外test.js的url应该是你的文件所在的路径,别弄错了哦,嘿嘿
下面给大家看看运行效果哦
http://www.bkjia.com/phpjc/992671.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/992671.htmltecharticlephp开发之ajax一 ajax这个东东前两天刚刚接触到,听别人说挺有用的哦,觉的有必要学一下。 下面就通过get方法传递参数到php页面为例来说一...
