renpei
var result="";
$.ajax({
    type: "post",
    url: "../reportRule/main.do?method=selectReportToAdd",
    data:{},
    success: function(msg){
        result = msg;
          alert(result );\\有数据
    }
});
alert(result)\\无数据
 

原因:

  ajax是异步请求,即javascript是非阻塞运行的,在$.ajax还没运行完alert命名可能就执行了,当然第二个alert的时候是没有数据的

解决办法:
  将ajax设置为同步请求,设置$.ajax的async属性为false

分类:

技术点:

相关文章:

  • 2021-12-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-15
  • 2021-09-01
  • 2021-10-15
猜你喜欢
  • 2021-07-22
  • 2021-10-18
  • 2022-12-23
  • 2021-10-16
  • 2022-12-23
  • 2021-09-20
相关资源
相似解决方案