在这里,我通过 JavaScript 从 HTML 页面获取值,从 ajax 访问该值并将该值传递给 PHP 页面。
PHP 页面应该使用该 ajax 值从表中删除,但 PHP 没有获得该 ajax 值...
这是我尝试过的:
JavaScript
var str;
function getResults(a)
{
str = a;
}
function showUser() {
if(str=="") {
document.getElementById("txtHint").innerHTML="";
return;
}
if(window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if(xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getmovie.php?q="+str,true);
alert(str);
xmlhttp.send();
}
PHP
<?php
$q = strtolower(trim($_GET["q"]));
try
{
$dbh = new PDO('mysql:dbname=theaterdb;host=localhost','tiger','tiger');
}
catch (PDOException $e)
{
echo 'Connection failed: ' . $e->getMessage();
}
$sql = 'DELETE FROM movie WHERE LOWER(movie_name) = :q';
$sth = $dbh->prepare($sql);
$sth->bindValue(':q', $q);
$sth->execute();
$dbh = null;
?>