OlympicDreamer
Senior Member
- Joined
- Mar 24, 2009
- Messages
- 1,145
- Reaction score
- 0
index.php
<head>
<script type="text/javascript">
function changePost(datetime)
{
var datetime = datetime;
alert(datetime);
var xhr;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE 8 and older
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
var data = "book_name=" + book;
xhr.open("POST", "book-suggestion.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(data);
}
</script>
</head>
<body>
<strong><i><a href="#" onClick="changePost(<?php echo $datetime;?>)">Previous</a></i></strong>
</body>
the script will not acho if I pass the variable $datetime when I call the function. why doesnt it work? I am trying to implement AJAX to call previous and next blog posts.
Working with Ajax, PHP and MySQL - Ajax Tutorials | w3resource
<head>
<script type="text/javascript">
function changePost(datetime)
{
var datetime = datetime;
alert(datetime);
var xhr;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE 8 and older
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
var data = "book_name=" + book;
xhr.open("POST", "book-suggestion.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(data);
}
</script>
</head>
<body>
<strong><i><a href="#" onClick="changePost(<?php echo $datetime;?>)">Previous</a></i></strong>
</body>
the script will not acho if I pass the variable $datetime when I call the function. why doesnt it work? I am trying to implement AJAX to call previous and next blog posts.
Working with Ajax, PHP and MySQL - Ajax Tutorials | w3resource