I have some number which are generated randomly . I need to get these numbers on server side i.e.$POST['number_array'].This "number_array" should include all the randomly generated numbers .Can anybody suggest me some way to do this. I am using PHP , Jquery , Javascript
3
-
Do you mean: $_POST['number_array']?vietean– vietean2011-08-11 12:06:00 +00:00Commented Aug 11, 2011 at 12:06
-
I don't know what did you do in client side: how about your html, javascript?vietean– vietean2011-08-11 12:08:11 +00:00Commented Aug 11, 2011 at 12:08
-
on client side i already have an array which has these number.. I just need to send this to server side . I am using javascript on client sideJAB– JAB2011-08-11 12:16:26 +00:00Commented Aug 11, 2011 at 12:16
Add a comment
|
4 Answers
Put []s after the name of the form element.
<input type="text" name="number_array[]" />
<input type="text" name="number_array[]" />
etc.
Then you can access the variables like so:
$number_array = $POST['number_array'];
$number_array[0];
If this is an ajax call, you can do it with jquery:
$.post("test.php", { 'number_array[]': [65, 45] }, function(data) {
alert("Data Loaded: " + data);
}););
EDIT: both 'number_array[]': [65, 45] and 'number_array': [65, 45] works fine, and " around javascript arrays are optional
1 Comment
vietean
I don't think that your fucntion is correct: You must
number_array: ["65", "45"], because ["65", "45"] is array.Let me summary what you need:
Client side with javascript
<script>
//If you have an array with 3 items with random value
var arrInt = [Math.random(),Math.random(),Math.random()];
//If you want to send it to file yourscript.php
//1. Using GET mothod
/*
$.get(
'yourscript.php',
{
number_array: arrInt
}
);
*/
//2. Using POST method:
$.post(
'yourscript.php',
{
number_array: arrInt
}
);
</script>
Server side with PHP:
<?php
//$arrInt = $_GET['number_array'];//If using GET
$arrInt = $_POST['number_array'];//If using POST
print $arrInt[0];
print $arrInt[1];
print $arrInt[2];
?>
1 Comment
JAB
exactly this is how i need.. let me try this