Hi Everyone,
I'm very hung up on a very simple function. I want to send a variable from a JavaScript function to a php file. It is not working. Can you point out what is wrong with my script because I checked the syntax several times and it looks fine to me. I don't know why it does not work:
http://leobee.com/sd9/missingGETvalues.gif
// main page
<body onload="postvar()">
<script>
function postvar(){
alert("postvar function ");
alert ($('#itemType').val());
$.get("test.php?", { itemType: 'poler' } );
}
</script>
//php processing page
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors',1);
$itemType='';
if (isset($_GET['itemType'])){
$_SESSION['itemType']=$_GET['itemType'];
echo "item type is ". $_SESSION['itemType'];
$itemType=$_SESSION['itemType'];
echo" item type is ".$itemType;
}else{ echo "item is not set ";}
?>
//out put displays 'item is not set'
The image above is from fiddler and it shows 200 ( ok) for the test.php. It also show the variable's name value pairs in the url.
The variable itemType shows nothing on the page.
Question:
Does the '&' need to be encoded? Do you have any suggestions on how to do that? do I encode it in javascript or is there a function to do it in php before the isset();?
Please let me know any reason SESSION variable does not work.
Any help is appreciated....