0

Please, help me to solve this problem

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>
0

1 Answer 1

1

try something like this

<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>';


?>
Sign up to request clarification or add additional context in comments.

1 Comment

i modify my code like this :<script type="text/javascript"> function get(){ $('#age').hide(); $.post('data.php',{ name: $('form').serialize() }, function (output){ $('#age').html(output).fadeIn(1000); }); } </script> <?php //data.php echo '<pre>'; print_r($_POST); echo '</pre>'; ?> but result showArray ( [name] => name%5B%5D=1&name%5B%5D=2 ) I want to get 1 by 1 value. so that I can collect data from database running a query to based on value thanks for help me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.