簡體   English   中英

使用Javascript將數據從一頁傳遞到另一頁有效,但頁面無法加載

[英]Pass data from one page to another using Javascript works but page doesn't load

我有一個頁面,那里有一個帶有按鈕的表格,當我單擊按鈕時,我將該值存儲在JS變量中,以便使用post將其發送到另一個頁面。

我在另一頁上獲取了值,但此后該頁面無法加載。

這是發送變量的按鈕代碼:

  <script>
function ObtenerDatosFila(oButton)
{
    var dgvVerGrupos = document.getElementById('dtBasicExample');

    $.ajax({
            url: 'FormularioAMGrupo.php',
            type: 'post',
            data: 
            {
               Modificar:'Modificar', 
               IDGrupo:dgvVerGrupos.rows[oButton.parentNode.parentNode.rowIndex].cells[0].innerHTML,
            },
            dataType: 'json',
            success:function(){}
        });

        return false;
    }   

    </script>
</script>

除了使用post方法之外,還有其他更簡單的方法嗎?

您可以建立一個頁面站點,而無需發送數據。 您必須稍微更改結構並將ajax函數更改為通用的“ ShowPage(id)”函數才能實現此目的。

如果您有興趣並且需要任何幫助,請這樣說。

按鈕的頁面:

<script>
function ObtenerDatosFila(oButton)
{
    var dgvVerGrupos = document.getElementById('dtBasicExample');

    localStorage.setItem("CodigoGrupo",dgvVerGrupos.rows[oButton.parentNode.parentNode.rowIndex].cells[0].innerHTML);
    localStorage.setItem("Modificar",'Modificar');

    location.href ="FormularioAMGrupo.php";
}   
</script>

第二頁:

 <script type="text/javascript">
    window.onload = alert(localStorage.getItem("CodigoGrupo"));
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM