简体   繁体   English

用jQuery重定向页面

[英]Redirect page with jquery

I have the following html code: 我有以下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>

as you can see there's a button that when i click call the function "dadosFormularios()"; 如您所见,有一个按钮,当我单击调用函数“ 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


    }

Now what i'm looking for is to use at the end of the above function something that redirects me to a php page (created by me) and receive there the array to treat the data he contains. 现在,我正在寻找的是在上述函数的末尾使用某种将我重定向到php页面(由我创建)的方法,然后在其中接收数组以处理他包含的数据。 I searched and found things like "window.location = "http://www.google.com";" 我搜索发现“ window.location =“ http://www.google.com”;“之类的内容。 and other similars but nothing is working here. 和其他类似内容,但此处无任何作用。 So if i can't redirect the page without clicking in a button i can't even think about passing vars with the redirection. 因此,如果我不能不单击按钮就无法重定向页面,那么我什至都不会考虑使用重定向传递变量。

A little help please. 请一点帮助。 Thank you! 谢谢!

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

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

Try document.location = your-url-here; 试试document.location = your-url-here; instead. 代替。

I'm thinking you might want to do something like this: 我在想您可能想做这样的事情:

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;

basically this puts all the data into a query string then tacks it onto the end of your url, which you can then access via your php script with $_GET. 基本上,这会将所有数据放入查询字符串中,然后将其添加到您的网址末尾,然后您可以使用$ _GET通过php脚本进行访问。 it will be something like 它会像

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

I think this is what you mean.... 我想这就是你的意思。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM