PHP get javascript array values

hi everyone.

I have this code:


$(document).ready(function() {
    $("#Botton1").click(function() {

    $("#Div2").load("folder1/file1.php", { 'Value[]': ["52"] } );

});


file1.php


<?php
    $U = $_POST(['UserID']);
?>

Well i am trying to get the values inside of the javascript array Value. i need some help with that and i need to know if i can only pass one value instead passing one value inside of an array.

Thanks community

In the PHP script, do a print_r($_POST) to see what values it contains.
And in case that jQuery sends the values in the query string (I have no idea) you might want to do a print_r($_GET) as well.

If you want to know how to pass non array values with jQuery, that’s a question for the JS forum. Just let us know if you want this thread moved to the JS forum (you can use the red report flag button to the left of each post for that).

Sorry, I don’t use jquery, but I can help you pass variables between JavaScript and PHP coded JavaScript

folder1/file1.php

<?php
header("ContentType: application/x-javascript");
header("Cache-Control: no-cache");
header("Expires: -1");

$userID=$_GET["userID"];

echo "alert(\\"".$userID."\\");";

?>

<head>
<script type="text/javascript">
function load(s){
 o=document.getElementsByTagName("head")[0];
 n=document.createElement('script');
 n.setAttribute('type', 'text/javascript');
 n.setAttribute('src',s);
 o.appendChild(n);
 delete n;delete o;
}
</script>
</head>
<button id="Botton1" onclick="load('folder1/file1.php?userID=52')">Click</button>

If the value you expect to get from the server-side javascript changes you’ll need the cache control, otherwise you can remove it to make it work faster.

change the querystring to pass through different values.

Edit: You might not want to name the function load() if you still use jquery after this.