【发布时间】:2013-02-15 23:00:32
【问题描述】:
我已经在 2 小时前就这个问题发表了一篇文章,但我真的需要尽快完成。
What I am trying to do is create a drop down container of 32 different locations in Scotland and when one of the selections is selected, for example, Glasgow it should go to a URL which displays content such as heading, text, for div WHERE location = Glasgow 中的每篇文章。
目前我没有每个位置的 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 时,它会显示正确的结果吗?
-
我已将我的答案移至原始问题,并投票决定将其作为重复问题关闭,好吗?
标签: php javascript onchange