Php 使用ajax刷新远程页面,以便在不刷新主页的情况下更新变量

Php 使用ajax刷新远程页面,以便在不刷新主页的情况下更新变量,php,javascript,ajax,Php,Javascript,Ajax,我正在尝试复制此网站的签出功能 我已经有了功能,但目前最重要的是,要更新的变量,我必须刷新页面,因此每当用户单击“添加到购物车”时,我就创建了window.location.reload函数,但我希望它与原始站点上的一样,页面不会重新加载。我的猜测是,我需要使用ajax刷新远程页面,但运气不好 function refreshData(str) { var str = "asd"; if (str=="") { wi

我正在尝试复制此网站的签出功能 我已经有了功能,但目前最重要的是,要更新的变量,我必须刷新页面,因此每当用户单击“添加到购物车”时,我就创建了window.location.reload函数,但我希望它与原始站点上的一样,页面不会重新加载。我的猜测是,我需要使用ajax刷新远程页面,但运气不好

function refreshData(str)
    {
        var str = "asd";
        if (str=="")
          {
          window.location.reload()//document.getElementById("displayarea").innerHTML="";
          return;
          } 
        if (window.XMLHttpRequest)
          {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
          }
        else
          {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        xmlhttp.onreadystatechange=function()
          {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {

            //popUpbox();
            //window.location.reload()

            //alert("<?php echo Process::items_in_cart(); ?>");//document.getElementById("displayarea").innerHTML=xmlhttp.responseText;
            }
          }
        xmlhttp.open("POST","<?php echo $base_url;?>process.php",true);
        xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        //xmlhttp.send("product_id=" + str);
    }
函数刷新数据(str)
{
var str=“asd”;
如果(str==“”)
{
window.location.reload()//document.getElementById(“displayarea”).innerHTML=“”;
返回;
} 
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
//popubox();
//window.location.reload()
//警报(“”;//document.getElementById(“displayarea”).innerHTML=xmlhttp.responseText;
}
}
open(“POST”,“process.php”,true);
setRequestHeader(“内容类型”,“应用程序/x-www-form-urlencoded”);
//xmlhttp.send(“product_id=“+str”);
}

让jquery尝试一下您想推荐的任何特定功能?因为jquery本身非常广泛。谢谢。首先,您可以通过使用
.ajax()
.get()
.post()
方法节省大量代码,而不是创建自己的
xmlhttp
对象,您还可以使用
.html()
.append()
和其他方法来刷新网页的特定部分而不刷新所有内容。实际上,我很想使用这些功能,但我还不太熟悉,我一直在网上搜索教程,但运气不好。请您为我指点一本关于这些功能的有用教程,谢谢。和