怎么样让提交的时候数据有提交更新,页面还是停留提交页面。

解决方案 »

  1.   

    使用ajax提交。
    给个例子你
    <input type="button" value="Add" onclick="SubmitGoods(<?=$result3['product_id']?>)"><script type="text/javascript">
    var xmlobj;                                  
    function CreateXMLHttpRequest() 
    {
        if (window.ActiveXObject)
        {
          var versions = ['Microsoft.XMLHTTP', 'MSXML6.XMLHTTP', 'MSXML5.XMLHTTP', 'MSXML4.XMLHTTP', 'MSXML3.XMLHTTP', 'MSXML2.XMLHTTP', 'MSXML.XMLHTTP'];      for (var i = 0; i < versions.length; i ++ )
          {
            try
            {
              xmlobj = new ActiveXObject(versions[i]);
              break;
            }
            catch (ex)
            {
              continue;
            }
          }
        }
        else
        {
          xmlobj = new XMLHttpRequest();
        }
    }function SubmitGoods(id)                        
    {
        CreateXMLHttpRequest();                    
        var product_id = id;
        var number_des = 'number_' + product_id;
     var number = document.getElementById(number_des).value;
        var parm = "product_id="+product_id + "&number=" +number;
        xmlobj.open("POST", "add_goods.php", true);    
        xmlobj.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;"); 
     xmlobj.send(parm);
     alert("Add to cart successfully!");  
    }function StatHandler()                          
    {
        if(xmlobj.readyState == 4 && xmlobj.status == 200)                                                                      //如果URL成功访问,则输出网页
        {
            alert("Add to cart successfully!");
        }
        else 
        {
            alert("Add to cart failed, please try again!");
        }
    }</script>
    </body>
    </html> 
      

  2.   

    提交之后更新数据,简单的做法是刷新当前页面或者白话一点就是跳回当前页面
    ajax是不刷新页面,而是刷新局部的数据
    根据你的个人需求来定制
      

  3.   

    不一定非要用ajax,当然ajax效率高点。
    你也可以使用框架来处理这个过程。
    <form action="submit.php" method="post" target="iframe">
    <input.............
    <input.............
    <input.............
    </form>
    <iframe id="iframe" name="iframe" width="0" height="0" marginwidth="0" frameborder="0" src="about:blank"></iframe>