这是问题,我有以下功能
$(document).ready(function() {
$('#selectTypeDD').change(function() {
var type = $("#selectTypeDD option:selected").text();
changeType(type);
alert(type);
});
});
当我选择下拉菜单中的城市时,警报会打印出pub
。
changeType就是这个功能
function changeType(type)
{
$.ajax
({
type: 'GET',
url: 'webservice.php',
data: {type: type},
success: function(response, textStatus, XMLHttpRequest)
{
alert("SUCCESS");
}
});
}
我在Firebug中得到了这个结果
pub[{"name":"The Master Builder","lon":"-1.34532","lat":"50.9303"},{"name":"Goblets","lon":"-1.40455","lat":"50.9088"},{"name":"Rat and Parrot","lon":"-1.40442","lat":"50.9085"},{"name":"The Victory Inn","lon":"-1.31415","lat":"50.8588"},{"name":"The King and Queen","lon":"-1.31356","lat":"50.8586"}
这个列表一直在继续,但我认为这些是最重要的。现在的问题是,我想对结果做一些事情并且它不起作用,所以我测试了为什么会这样,并在成功函数中输入alert("SUCCESS")
。但它甚至没有打印出警报。为什么?我究竟做错了什么? werbservice运行没有问题。当我打开我的网站localhost / blabla / webservice.php?type = pub时,它打印出所有内容。那可能是什么问题?
这是我的网络服务的一方
else if(isset($_GET['type']))
{
$type = $_GET['type'];
echo $type;
if($result = $mysqli->query("SELECT name, lon, lat FROM pointsofinterest WHERE type = '".$type."'"))
{
$tempArray = array();
while($row = $result->fetch_assoc())
{
$tempArray = $row;
array_push($array, $tempArray);
}
echo json_encode($array);
}
}
答案 0 :(得分:0)
改变你的
success: function(response, textStatus, XMLHttpRequest)
到
success: function(response)