+ -
当前位置:首页 → 问答吧 → ajax问题

ajax问题

时间:2010-10-28

来源:互联网

JScript code
function createXmlHttp()
{
    if(window.XMLHttpRequest)
        xmlHttp=new XMLHttpRequest();
    else
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
function AddToCart(bid)
{
    if(!xmlHttp)
        createXmlHttp();
    xmlHttp.onreadystatechange=showMessage;
    xmlHttp.open("get","workasp/AddToCart.aspx?bid="+bid,true);
    xmlHttp.send(null);
}
function showMessage()
{
    if(xmlHttp.readyState==4)
    {
        if(xmlHttp.status==200)
        {
            alert(xmlHttp.responseText);
        }
    }
}

为什么上边的showMessage()方法就只在第一次调用AddToCart()时执行,以后再调时请求时发送了,就是不走showMessage
只是IE(我用的是ie6)出问题,火狐和chorme我试过都没有问题

作者: zhou695105338   发布时间: 2010-10-28

缓存问题。加时间戳
JScript code
xmlHttp.open("get","workasp/AddToCart.aspx?bid="+bid+'&_dc='+new Date().getTime(),true);

作者: showbo   发布时间: 2010-10-28

放弃IE6,ie6不标准。

作者: chen_ya_ping   发布时间: 2010-10-28

热门下载

更多