【问题标题】:jQuery Success Function doesn't alertjQuery成功函数不提醒
【发布时间】:2026-01-16 00:25:01
【问题描述】:

这就是问题所在,我有以下功能

$(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);
}
}

【问题讨论】:

  • 你试过error回调了吗?
  • source : function(request, response) 你可以试试这个。
  • 将警报放入error: function(response) 以确保您的服务器调用正常
  • 是的,我遇到了一个错误。可能是什么问题?

标签: php jquery html json web-services


【解决方案1】:

改变你的

success: function(response, textStatus, XMLHttpRequest)

success: function(response)

【讨论】:

  • 还是什么都没有。没有alert("SUCCESS");