小编dwe*_*lch的帖子

problems executing a jquery ajax call within a function

I would like to put an ajax call within a function since I use it repeatedly in multiple locations. I want a manipulated version of the response returned. Here's what I'm trying to do (greatly simplified).

a = getAjax();
$('body').append('<div>'+a+'</div>');
function getAjax() {
  $.ajax({
   type: "GET",
   url: 'someURL',
   success: function(response) {
     return response;
  });
}
Run Code Online (Sandbox Code Playgroud)

然而,正在发生的是,在getAjax函数中定义"a"之前,append函数正在运行.有什么想法吗?

javascript ajax jquery

8
推荐指数
2
解决办法
3万
查看次数

标签 统计

ajax ×1

javascript ×1

jquery ×1