jQuery ajax相关问题

问题描述

| 我试图找出,我在下面的代码做错了什么:
$(function() {
   $(\".alert\").live(\'click\',function(){
      var id = $(this).closest(\"tr\").attr(\"id\")
      var info = \'id=\' + id;
      $.ajax({
         type: \"POST\",url: \"http://localhost/app/ajax.php?act=alert\",data: info,success: function(Response){
           }
      });
   alert(Response);
   $(this).hide();
   return false;
   });
});
Return false
不起作用。 HTML代码:
<a href=\"#\" class=\"alert\">Alert</a>
    

解决方法

根据定义,AJAX是异步的。 当您的
$.ajax
呼叫返回时,HTTP请求仍将得到处理,因此
Response
还不会被填充。 将
alert(Response)
调用放入
success
回调中以查看其工作方式。     

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...