我已经就这个问题发了一篇文章,不超过2小时,但我真的需要尽快完成。无法让我的javascript/php onchange功能正常工作
我想要做的是创建一个在苏格兰的32个不同位置的下拉式容器,当选择其中一个选项时,例如格拉斯哥,它应该转到显示标题,文本等内容的URL。对于div中的每篇文章WHERE位置=格拉斯哥。
目前我没有每个位置的URL。
我时,我选择了新的选项下面的消息:“加载结果:成功||| 200 OK”
有人能这么好心给我提供的最后一块这个令人沮丧的难题?
这里是我的文件正在使用:
的header.php
<html>
<head>
<script src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#location').change(function(){
//Retrieve Content from the back-end PHP page, and pass the ID selected
var url = 'location.php?location=' + $(this).val();
$('#txtHint').load(url, function (response, status, xhr) { alert("Load result: " + status + " ||| " + xhr.status + " " + xhr.statusText);
});
});
});
</script>
</head>
<body>
<div id="header">
<div class="headerLeftContent">
<select id="location">
<option value="Glasgow">Glasgow</option>
<option value="x">x</option>
<option value="test">test</option>
<option value="Edinburgh">Edinburgh</option>
</select>
<div id='txtHint'></div>
</div>
</div>
</body>
</html>
location.php
<?php
$connect = mysql_connect('xxx', 'xxx', 'xxx');
$select_db = mysql_select_db('xxx');
$location = $_REQUEST['location'];
$query = "SELECT * FROM podContent WHERE location = '.$location.'";
$result = mysql_query($query, $connect);
while($row = mysql_fetch_array($result))
{
echo $row['text'];
}
?>
感谢。
您是否试图使用Firebug JavaScript调试器在Mozilla中加载?它显示了所有的JS错误。当你直接调用location.php时,它是否显示正确的结果? – Andrew 2013-02-15 23:03:59
[创建onChange选择下拉使用JavaScript和PHP,但它不工作]可能重复(http://stackoverflow.com/questions/14903822/creating-an-on-on-select-drop-down-with-javascript-and -php-but-it-not-worki) – bfavaretto 2013-02-15 23:09:40
我将我的答案移至原始问题上,并且投票结束这个重复的问题吗? – bfavaretto 2013-02-15 23:10:49