0

我有一个调用 javascript onclick 的图像。验证后,我调用一个将记录添加到数据库并返回的目标文件。我的代码看起来像这样

......

xmlhttp.open("GET","addrecord.php?iddesc=gold&tid=t_id&pid=p_id",true);
xmlhttp.send();

插入记录后,它返回 echo "insert done";我的xmlhttp.open()上面的代码是这样的

xmlhttp.onreadystatechange=function()
                {
                  if (xmlhttp.readyState==4 && xmlhttp.status==200)
                  {
                    //alert("id is "+id);
                    document.getElementById(id).innerHTML=xmlhttp.responseText;
                }
            }

当我在浏览器上执行此代码时,会调用 js。我在所有地方都有警报,我能够跟踪代码流,直到 xmlhttp.open(); 但什么也没发生。我可以通过其他测试程序独立调用目标 php 文件。

4

1 回答 1

0

好的,我发现这是由我的图像所在的锚点上的 href 引用引起的。当我删除 href 时,我可以访问 ajax GET 或 POST。

现在我必须弄清楚如何拥有 href 和 ajax。我相信一定有办法。

不知道为什么 href 优先于 ajax 的 xmlhttp.request()。

于 2012-05-07T12:00:06.157 回答