Php 意外标记
我一直在犯这样的错误,而就我的一生而言,我不知道到底是什么导致了这个错误。我试图做的是从数据库中检索一些数据并将其显示在页面上,但我无法做到Php 意外标记,php,json,ajax,Php,Json,Ajax,我一直在犯这样的错误,而就我的一生而言,我不知道到底是什么导致了这个错误。我试图做的是从数据库中检索一些数据并将其显示在页面上,但我无法做到 xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { if (xmlhttp.responseText != null || xmlhttp.responseText !=
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
if (xmlhttp.responseText != null || xmlhttp.responseText != "That email does not exist in our database") {
var json = JSON.parse(xmlhttp.responseText);
var image = json[0]; // or json["Data"]
document.getElementById("dp").innerHTML = image;
} else {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
}
xmlhttp.open("GET", "getemail.php?q=" + str, true);
xmlhttp.send();
这就是我进行检索的文件
$q = $_GET['q'];
$data = [];
if (!$link) {
die('Could not connect: ' . mysqli_error($link));
}
$sql="SELECT officer_name FROM officer WHERE email = '$q'";
$result = mysqli_query($link,$sql);
$getName = mysqli_fetch_assoc($result);
$name = $getName['officer_name'];
if($name == null){
echo "That email does not exist in our database";
} else {
$sql2="SELECT picture, officer_name FROM officer WHERE email = '$q'";
$result2 = mysqli_query($link,$sql2);
$getItems = mysqli_fetch_array($result2);
$pic = $getItems['picture'];
$name = $getItems['officer_name'];
$data = ["image" => "<img style='height:150px; width:150px;' src='image/" . $pic . "'>", "email" => "$q"];
echo $data;
}
mysqli_close($link);
控制台指向行var json=json.parsexmlhttp.responseText;至于错误在哪里。我很抱歉,如果解决方案看起来有点明显,我只是刚刚开始涉足这一领域。感谢您提供的帮助。这里非常接近您的ajax。我没有您的js引用的所有其他内容,因此部分内容将按原样失败:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script>
$(document).ready(function() {
$("#clicker").click(function() {
var str = 'test';
$.ajax({
url: "getemail.php",
type: 'get',
data: { q: str },
success: function(response) {
if(response != null)
$("#dp").html(response);
else
$("#txtHint").html("That email does not exist in our database");
}
});
});
});
</script>
<div id="clicker">CLICK</div>
<div id="dp">load into</div>
<div id="txtHint">txtHint text hing</div>
通常,当我收到这个错误时,这意味着我没有从PHP返回json,而是以错误的形式返回html。检查您的php是否正在运行脚本,并且没有错误。当我运行php文件本身时,我能够获得要显示的所需数据。在相关行之前,只需执行console.logxmlhttp.responseText;然后通过控制台查看返回的内容。您尝试过jQueryAjax吗?这非常简单。为了那个人,你可能想从你的评论中删除这封邮件:谢谢!我将继续这个例子。我只是快速编辑并添加了$document.readyfunction{};包装纸。没有这一点,它可能什么也做不了。