簡體   English   中英

用jQuery重定向頁面

[英]Redirect page with jquery

我有以下html代碼:

    <form method="post" name="b" >
<table>
    <tr>
        <td>Field A</td>
        <td><input type='text' name='field[0][a]' id='field[0][a]'></td>
        <td>Field B</td>
        <td><textarea name='field[0][b]' id='field[0][b]'></textarea></td>
        <td><button>remove</button></td>
    </tr>
</table>
</div>
<div id="container"></div>
<button id="mybutton">add form</button>

<div align="center">
<p><button onClick="dadosFormularios()" value="Registar" name="registar">Registo</button></p>
</div>
</form>

如您所見,有一個按鈕,當我單擊調用函數“ dadosFormularios()”;

  function dadosFormularios(){

            var dadosFormulario={};
            var iterador=countForms;
            var i=0;

            while(i<iterador){

            dadosFormulario[i]={};
            dadosFormulario[i]['a']=$('#field\\['+i +'\\]\\[a\\]').val();
            dadosFormulario[i]['b']=$('#field\\['+i +'\\]\\[b\\]').val();   
            alert(dadosFormulario[i]['a']);
            alert(dadosFormulario[i]['b']); 
                i++;
            }

//i want to redirect here


    }

現在,我正在尋找的是在上述函數的末尾使用某種將我重定向到php頁面(由我創建)的方法,然后在其中接收數組以處理他包含的數據。 我搜索發現“ window.location =“ http://www.google.com”;“之類的內容。 和其他類似內容,但此處無任何作用。 因此,如果我不能不單擊按鈕就無法重定向頁面,那么我什至都不會考慮使用重定向傳遞變量。

請一點幫助。 謝謝!

您不需要jQuery來重定向,只需javascript

window.location.href="page.html";

試試document.location = your-url-here; 代替。

我在想您可能想做這樣的事情:

var qstring = '';
var tmp_qstring = [];
for ( var i = 0; i < dadosFormulario.length; i++ )
{
       tmp_qstring[i] = 'a' + i + '=' + dadosFormulario[i]['a'] + '&' + 'b' + i + '=' + dadosFormulario[i]['b'];

}

qstring = tmp_qstring.join('&');

window.location = 'page.php?' + qstring;

基本上,這會將所有數據放入查詢字符串中,然后將其添加到您的網址末尾,然后您可以使用$ _GET通過php腳本進行訪問。 它會像

page.php?a1=val&b1=val&a2=val&b2=val...

我想這就是你的意思。

暫無
暫無

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

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