如何使用jQuery在另一个PHP文件中发送动态数组值 [英] How to send dynamic array value in another php file using jQuery

查看:58
本文介绍了如何使用jQuery在另一个PHP文件中发送动态数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请帮我解决这个问题

当我尝试单一输入值时,输入值成功传输了data.php文件,并且我在data.php文件中获得了输入值,以编写此代码.echo $ name = $ _ POST [‘name’];但是我可以在data.php文件中传输输入数组的值,实际上我对jquery的了解不足.因此,任何人都可以帮助我解决这个问题.用于在data.php文件中传输数组值的write jQuery代码是什么,以及用于echo的write php代码是什么.

When I am trying Single input value then input value transfer data.php file successfully and I get input value in data.php file to write this code echo $name=$_POST[‘name’]; but I can transfer input array value in data.php file, actually I have not enough knowledge about jquery. So anyone can help me to solve this problem. What’s the write jquery code for transferring array value in data.php file and what’s the write php code for echo.

    <script type="text/javascript" src="jquery.js"></script>

    <script type="text/javascript">

        function get(){
            $('#age').hide();
            $.post('data.php',{ name: form.name.value }, 

             // this code don't work in array

            // how can i transfer name[] value in data.php file

        function (output){
            $('#age').html(output).fadeIn(1000);
        });
        }

    </script>
    <body>
    <form name="form" action="a.php">

        <input type="text" name="name[]" value="1"/>
        <input type="text" name="name[]" value="2"/>
        <input type="button" value="Get" onclick="get();"/>
    </form>

    <div id="age">

    </div>
</body>

推荐答案

尝试类似的方法

<form>
<input name="name[]" value="1" />
<input name="name[]" value="2" />
</form>


$.post('data.php',$('form').serialize(), function(data) {
   alert('success');  /// console.log(data); use this rather than alert with firebug
});


<?php 
//data.php

echo '<pre>';
print_r($_POST);
echo '</pre>';


?>

这篇关于如何使用jQuery在另一个PHP文件中发送动态数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆