1

你能帮我处理这段代码吗?

    function blub() {

    $.ajax({
    type: 'GET',
    url: 'blups1.php?rid=10',
    async: true,
    cache: false,
    dataType: 'json',
    success: function(data){

         var name = data[0].name;
         alert('ok = '+name);


    },
    error: alert('nix gefunden')
    });


}

如果成功,它会告诉我我想要什么,但错误警报总是首先弹出。我必须在哪里放置该错误警报,以便它仅在没有数据库时出现?

4

1 回答 1

2

I'm really not sure why one would just place the alert statement singularly as the callback. Put the alert in a function:

error: function(xhr, status, error) {
  alert('nix gefunden');
}
于 2013-08-01T08:04:48.327 回答