Hi all!
I have a problem which I can't seem to fix. I would like to know is it possible to send a normal JS variable to a php page. I've tried the following and nothing seems to work.
<input type="submit" value="Bookmark" onclick="bookmark();">
function bookmark() {
var pageNum = 2;
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp = new XMLHttpRequest();
}else{
alert("Not assigned!");
}
xmlhttp.open("GET", "Bookmark.php?pageNum="+pageNum, true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); with or without this it doesn't work
xmlhttp.send();
alert("Bookmark send!");
}
Then in the php:
$pageNum = $_GET['pageNum'];
echo "Page numbers:" + $pageNum;
I've tried post aswell and I've tried
var pageNum = 'pageNum=' + 2;
xmlhttp.open("POST", "Bookmark.php", true);
xmlhttp.send(pageNum);
php:
$pageNum = $_POST['pageNum'];
echo "Page numbers:" + $pageNum;
any help will be appreciated!
Thanks!