1
<form enctype="multipart/form-data" method="post" name="settingsForm" id="settingsForm">
        Admin Name: <input type="text" value="Vipul Sharma" name="admin[admin_name]" id="admin_name"><br>
        Admin Email: <input type="text" value="vsharma1@seasiaconsulting.com" name="admin[admin_email]" id="admin_email"><br>
        Site Logo: <input type="file" name="site[logo]" id="site_logo"><img width="150px" height="100px" src="http://localhost/grublies/public/images/Atomic-Bomb-Explosion-600x450.jpg"><br>
        Records Per Page in user side: <input type="text" value="12" name="admin[rpp_user]" id="rpp_user"><br>
        Records Per Page in admin side: <input type="text" value="15" name="admin[rpp_admin]" id="rpp_admin"><br>
        Site Address: <textarea name="admin[site_address]" id="site_address">C 136</textarea><br> <input type="submit" value="Submit" id="" name=""> </form>

如果我在 php 中提交表单后使用 post 方法,那么它会创建一个像这样的数组

Array
(
    [admin] => Array
        (
            [admin_name] => Vipul Sharma
            [admin_email] => vsharma1@seasiaconsulting.com
            [rpp_user] => 12
            [rpp_admin] => 15
            [site_address] => C 136
        )

)

但我希望通过 jQuery ajax 发布相同的数组,但不幸的是它考虑 admin[admin_name] 作为变量。我使用了 jQuery 序列化,它不起作用?

4

1 回答 1

0

我认为这会对您有所帮助我已经更改了您 HTML 中的一些属性,请仔细查看表单提交

<html>
    <script src="jquery-1.7.2.js"></script> 
<head>
</head>
<body>
    <div id="mainfomr">
<form enctype="multipart/form-data" method="post" name="settingsForm" id="settingsForm">
        Admin Name: <input type="text" value="Vipul Sharma" name="admin[admin_name]" id="admin_name"><br>
        Admin Email: <input type="text" value="vsharma1@seasiaconsulting.com" name="admin[admin_email]" id="admin_email"><br>
        Site Logo: <input type="file" name="site[logo]" id="site_logo"><br>
        Records Per Page in user side: <input type="text" value="12" name="admin[rpp_user]" id="rpp_user"><br>
        Records Per Page in admin side: <input type="text" value="15" name="admin[rpp_admin]" id="rpp_admin"><br>
        Site Address: <textarea name="admin[site_address]" id="site_address">C 136</textarea><br> <input type="button" value="Submit" id="formsubmit" name=""> </form>
</body>
<script>
    $("#mainfomr").on("click", "#formsubmit", function(event){

        var order = $("#settingsForm").serialize()
     $.post("yourphpfile.php",order, function(data){

     });
    });
    </script>
</html>
于 2012-10-09T06:44:10.823 回答