I would like to know how I can pass a Javascript
array from Javascript
to PHP
through Jquery/Ajax
. In fact I created two files: t1.html
and moslem3.php
. The code of each file is below:
The code of t1.html:
<html>
<head>
</head>
<body>
<script type="text/javascript">
$(document).ready(function() {
var table = ["actor", "subject", "object"];
$.ajax({
type: "POST",
url: 'moslem3.php',
data: table
});
});
</script>
</body>
</html>
The code of moslem3.php:
<?php
$myArray = $_REQUEST['table'];
echo $myArray;
?>
The file moslem3.php
displays this message:
Notice: Undefined index: table in C:\wamp\www\test1\moslem3.php on line 2
So my question is: where is the wrong here exactly?..Is there any one who has any idea?
Thanks in advance.
echo json_encode($myArray);
– Think Different May 27 at 15:57success: function(result){ .... }
. BTW your ajax call need tweaking. – Think Different May 27 at 15:58