var pload = function(ctrl, func){
var dataa;
$.post("/index.php/"+ctrl+"/"+func,{}, function(data){
dataa = data;
});
return dataa;
};
var bind = function(hashtag, ctrl, func, div){
$(document).on("click", "a[href="+hashtag+"]", function() {
var body = pload(ctrl, func);
alert(body);
$(div).html(body);
})
}
How I can get data in global? I want, so pload
return data from post request. But I get "undefined" in alert()
tyr this:
You're not getting any value back because
$.post
is asynchronous, and won't halt the program until it receives a value back.You should move the data handling portion to the function which will be called when the async call returns its result.
Try using callback.