jQuery $.ajax success must be a callback function?
Posted
by b. e. hollenbeck
on Stack Overflow
See other posts from Stack Overflow
or by b. e. hollenbeck
Published on 2010-03-28T00:40:35Z
Indexed on
2010/03/28
0:43 UTC
Read the original article
Hit count: 607
I've created a wrapper function for jQuery's $.ajax() method so I can pass different dataTypes and post variables - like so:
function doPost(dType, postData, uri){
$.ajax({
url: SITE_URL + uri,
dataType: dType,
data: postData,
success: function(data){
return data;
});
}
The problem I'm having is getting the data (which is always JSON) back out. I've tried setting a var ret
before the $.ajax() function call and setting it as ret = data
in the success function. Am I being stupid about this? If I don't set a success function, will the $.ajax simply return the data? Or is it just success: return data
? Or does success
require a callback function to handle the data, which could just be return data
?
© Stack Overflow or respective owner