Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AJAX responseText在GET请求到.php后未定义_Php_Javascript_Html_Ajax_Responsetext - Fatal编程技术网

AJAX responseText在GET请求到.php后未定义

AJAX responseText在GET请求到.php后未定义,php,javascript,html,ajax,responsetext,Php,Javascript,Html,Ajax,Responsetext,我试图从mySQL数据库中提取设备列表,然后将其格式化为my.php中的html select/option元素,然后回显要插入主页的html字符串,但它不会将回显的字符串返回到responseText 下面是我的.php: <?php $dbhost = "localhost"; $dbuser = "root"; $dbpass = "admin"; $dbname = "devices"; //Connect to MySQL Server $con=mysql_connec

我试图从mySQL数据库中提取设备列表,然后将其格式化为my.php中的html select/option元素,然后回显要插入主页的html字符串,但它不会将回显的字符串返回到responseText

下面是我的.php:

<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "admin";
$dbname = "devices";
    //Connect to MySQL Server
$con=mysql_connect($dbhost, $dbuser, $dbpass);
    //Select Database
mysql_select_db($dbname) or die(mysql_error());

$sql="SELECT DISTINCT device_name FROM device_graphs";
$result=mysql_query($sql, $con);

$responsetxt="Hello all :)";
$counter=0;
while($row = mysql_fetch_array($result))
{
    $responsetxt .= "<option value=$counter>$row[0]</option>";
    $counter++;
}

echo $responsetxt;

?>
ajaxresponse在我每次尝试时都是未定义的;它只会弹出两个空的javascript警报框。如果我在浏览器中只运行.php,我会得到正确的输出,并回显到我的窗口中,因此我认为这不是php的问题,除非通过ajax通过php传递html有问题

以下是下拉代码的其余部分:

function deviceDropdown_pt2(monNum, ajaxresponse, insideHTML)
{
//Sets the action to occur when a selection is made in the device dropdown, 
//  in this case the properties dropdown menu
insideHTML=insideHTML + "<select onchange='propertiesDropdown(this.options[this.selectedIndex].value, " +  monNum + ")'>";  
insideHTML=insideHTML + "<option value=\"-1\">-Select a Device-</option>";
insideHTML = insideHTML + ajaxresponse; 
insideHTML=insideHTML + "</select>";
}
你应该使用

您想要实现的目标的简单示例:

$.get('ajax/test.html', function(data) {
    $('.result').html(data);
    alert('Load was performed.');
});
您所要做的就是在标题中包含以下内容:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script
您应该使用

您想要实现的目标的简单示例:

$.get('ajax/test.html', function(data) {
    $('.result').html(data);
    alert('Load was performed.');
});
您所要做的就是在标题中包含以下内容:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script

此问题可能与您的ajaxRequest有关。考虑使用像jQuery这样的库来轻松和安全地处理Ajax请求。对于一个,在您完成PHP之前,将其设置为“”,初始化您的$ReffStxt变量。其次,我知道您可以通过AJAX请求发送HTML,所以这不是问题。@JasonKaczmarsky抱歉,我确实初始化了它,我只是忘了将它粘贴到这里,因为我一直在玩它,并将它初始化为“Hello:)”,以查看是否可以传递非HTML代码。我已经更新了上面的代码来反映这一点;{$row[0]}。不是强制性的,但建议使用。请尝试发出警报(response.toString())并查看它是否向对象发出警报。此问题可能与您的ajaxRequest有关。考虑使用像jQuery这样的库来轻松和安全地处理Ajax请求。对于一个,在您完成PHP之前,将其设置为“”,初始化您的$ReffStxt变量。其次,我知道您可以通过AJAX请求发送HTML,所以这不是问题。@JasonKaczmarsky抱歉,我确实初始化了它,我只是忘了将它粘贴到这里,因为我一直在玩它,并将它初始化为“Hello:)”,以查看是否可以传递非HTML代码。我已经更新了上面的代码来反映这一点;{$row[0]}。不是强制性的,但建议使用。请尝试发出警报(response.toString())并查看它是否向对象发出警报。