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函数正在运行.有什么想法吗?