Javascript AJAX没有';不要发回
首先我想说我是Ajax的初学者。我只是个初学者。我希望你能帮我 我想向ajax脚本发送一个id,然后在那里运行一个查询。然后我想返回页面的输出。我有一个页面quick_view_page.js,我在其中设置id并将其发送到ajax_project_info.php,在其中通过链接检索id。如果我打开ajax_project_info.php并在链接中设置一个变量id,它会工作得很好 我无法将ajax\u项目信息的输出返回到quick\u view\u page.jsJavascript AJAX没有';不要发回,javascript,php,ajax,Javascript,Php,Ajax,首先我想说我是Ajax的初学者。我只是个初学者。我希望你能帮我 我想向ajax脚本发送一个id,然后在那里运行一个查询。然后我想返回页面的输出。我有一个页面quick_view_page.js,我在其中设置id并将其发送到ajax_project_info.php,在其中通过链接检索id。如果我打开ajax_project_info.php并在链接中设置一个变量id,它会工作得很好 我无法将ajax\u项目信息的输出返回到quick\u view\u page.js //Quick view s
//Quick view show and hide
$('a#quick_view').click(function() {
var projectId = $(this).find($(".qv_id")).attr('id');
//alert(projectId);
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","ajax/ajax_project_info.php?projectId=" + projectId);
xmlhttp.send();
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementByClassName("qvp_bg").innerHTML=xmlhttp.responseText;
}
我的快速查看页面.js
//Quick view show and hide
$('a#quick_view').click(function() {
var projectId = $(this).find($(".qv_id")).attr('id');
//alert(projectId);
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET","ajax/ajax_project_info.php?projectId=" + projectId);
xmlhttp.send();
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementByClassName("qvp_bg").innerHTML=xmlhttp.responseText;
}
我的ajax_项目_info.php
<?php
require_once("../pages/db.php");
error_reporting(E_ALL);
ini_set('display_errors', 1);
ob_start();
$projectId = $_GET["projectId"];
$query_getinfo = "SELECT * FROM tblProjecten WHERE id = '".$projectId."'";
$result_query_getinfo = mysqli_query($conn,$query_getinfo);
while ($row = mysqli_fetch_array($result_query_getinfo)) {
$response = $row['projectnaam'];
};
else {
$response = "Geen info beschikbaar";
}
return $response;
ajax_project_info.php:
<?php
/*
require_once("../pages/db.php");
error_reporting(E_ALL);
ini_set('display_errors', 1);
ob_start();
$projectId = $_GET["projectId"];
if ($projectId) {
$query_getinfo = "SELECT * FROM tblProjecten WHERE id = '".$projectId."'";
$result_query_getinfo = mysqli_query($conn,$query_getinfo);
while ($row = mysqli_fetch_array($result_query_getinfo)) {
$response = $row['projectnaam'];
}
else {
$response = "Geen info beschikbaar";
}
}
else {
$response = "Geen info beschikbaar";
}
echo $response;
*/
echo "test";
它给出了以下错误:“未定义xmlhttp”。使用echo$response
而不是return$response
试试看
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementByClassName("qvp_bg").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax/ajax_project_info.php?projectId=" + projectId, true);
xmlhttp.send();
使用jQuery
将jQuery包含到项目中
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
希望这有帮助:-)使用echo$response
而不是return$response
试试看
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementByClassName("qvp_bg").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","ajax/ajax_project_info.php?projectId=" + projectId, true);
xmlhttp.send();
使用jQuery
将jQuery包含到项目中
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
希望这有帮助:-)更改返回$response;回应,;谢谢你的回复。我把“返回”改为“回声”。但它仍然不起作用。我还将getElementByClassName(“qvp_bg”)更改为getElementsByClassName(“qvp_bg”)。我在chrome inspect元素中没有错误。更改返回$response;回应,;谢谢你的回复。我把“返回”改为“回声”。但它仍然不起作用。我还将getElementByClassName(“qvp_bg”)更改为getElementsByClassName(“qvp_bg”)。我在chrome inspect元素中没有错误。非常感谢您的回复。我把“返回”改为“回声”。但它仍然不起作用。我还将getElementByClassName(“qvp_bg”)更改为getElementsByClassName(“qvp_bg”)。我在chrome inspect元素中没有错误。在chrome inspect元素的“网络”下没有任何错误?真奇怪。。也许你的PHP有错误。试着只放echo“test”
在你的ajax\u项目\u info.php
中,看看会发生什么。我已经在ajax\u项目\u info.php中使用echo“test”进行了测试。还是没什么。chrome中的“网络”选项卡中没有错误。我还使用if(xmlhttp.readyState==4&&xmlhttp.status==200){alert(“test”)}进行了测试,它既不提供警报框,也不提供ajax_project_info.php自己工作的警报框?另外,您是否考虑过使用jQuery?也可以试试,xmlhttp.open(“GET”,“ajax/ajax\u project\u info.php?projectd=“+projectd,true”)代码>非常感谢您的回复。我把“返回”改为“回声”。但它仍然不起作用。我还将getElementByClassName(“qvp_bg”)更改为getElementsByClassName(“qvp_bg”)。我在chrome inspect元素中没有错误。在chrome inspect元素的“网络”下没有任何错误?真奇怪。。也许你的PHP有错误。试着只放echo“test”
在你的ajax\u项目\u info.php
中,看看会发生什么。我已经在ajax\u项目\u info.php中使用echo“test”进行了测试。还是没什么。chrome中的“网络”选项卡中没有错误。我还使用if(xmlhttp.readyState==4&&xmlhttp.status==200){alert(“test”)}进行了测试,它既不提供警报框,也不提供ajax_project_info.php自己工作的警报框?另外,您是否考虑过使用jQuery?也可以试试,xmlhttp.open(“GET”,“ajax/ajax\u project\u info.php?projectd=“+projectd,true”)代码>