看了某视频教程,但我怎么弄也不对,跟群里人也研究大半宿,可我这还是不对,主要就是怎么弄都不出ajax的效果
for.php
if($id = $_GET[id])
 {
  for($i = 1;$i<10;$i++)
  {
  echo $id;
  }
  exit();
 }ajax.jsvar xmlHttp;
function S_xmlhttprequest()
{
if(window.ActiveXObject)
{
xmlHttp = new xmlActiveXObject('Microsoft.XMLHTTP');
}else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest(); }
}function funphp100(url)
{
S_xmlhttprequest();
xmlHttp.open("GET","for.php?id="+url,true);
xmlHttp.onreadysatechange = byphp;
XmlHttp.send(null);
}function byphp()
{
var byphp100 = xmlHttp.responseText;
document.getElementById('php100').innerHTML = byphp100;
}<script type = "text/javascript" src = "ajax.js"></script><a href = "#" onclick="funphp100('o')">o</a>
<a href = "#" onclick="funphp100('t')">t</a>
<a href = "#" onclick="funphp100('x')">x</a><div id="php100"></div>

解决方案 »

  1.   

    非常简单:
    xmlHttp.open("GET","for.php?id="+url,true);这之中的url构建有问题,需要加个随机数,防止服务器使用缓存.xmlHttp.open("GET","for.php?id="+url+"&randomId="+Math.random(),true);
      

  2.   

    function A_xmlhttprequest() {
        if(window.ActiveXObject) {
            xmlHttp = new ActiveXObject('Microsoft.XMLHTTP');
        } else if(window.XMLHttpRequest) {
            xmlHttp = new XMLHttpRequest();
        }
    }function funphp100(url) {
        A_xmlhttprequest();
        xmlHttp.open("GET","for.php?id="+url,true);
        xmlHttp.onreadystatechange = byphp;   //xmlHttp一打开for页面(发生改变)就执行byphp方法。
        xmlHttp.send(null);
    }function byphp() {                var change  =  xmlHttp.responseText;      //把xmlHttp.responseText中的内容放在变量change中
              document.getElementById('php100').innerHTML = change;  //change中的内容传递到显示页面的‘PHP100’的标签中。这是群里的一个帮我研究大半宿的哥们给弄的,但我就是无法保存总出现这个:
    使用iso-8859-1无法映射某字符,更改编码或除去字符编码不支持的字符
      

  3.   

    xmlHttp.onreadysatechange = byphp;
    大哥是这样写的  
    xmlHttp.onreadystatechange = byphp;
      

  4.   


    查看你当前文档的编码是不是iso-8859-1,或者你复制粘贴了另外一种编码格式的代码,统一下编码
      

  5.   

    另外你的byphp函数可能还要添加一些代码,因为AJAX与服务器交互时会有5种状态:0,1,2,3,4
    其中4为接到服务器响应,添加一些必要的判断使结果更准确