This is the code that is working but not the way i need it too, ill explain it after.
getRegisterFiles('regster1')
function getRegisterFiles(name) {
var request = $.ajax({
url: "/../files/Users/"+name+".ctp",
type: "GET",
dataType: "html"
});
request.fail(function(jqXHR, textStatus) {
$('#pageLoading p').html('We have experienced a problem. Please try again later.');
return false;
});
request.success(function(msg) {
placeData(msg);
});
}
function placeData(registerData) {
$('#pageWrap').html(registerData);
}
So the code above gets a .ctp file and then displays it on screen.
What i need it to do
Instead of having the placeData(msg) in the success part i want to return the contents of 'msg' to a variable that will initiate the function like so,
register = getRegisterFiles('register1');
I have tried using,
return msg;
but it doesn't work... If i use return msg and then 'alert' it it comes up as undefined.
I have no idea what todo next so any ideas will be greatly welcomed. Sorry if its a complete newb mistake.
EDIT --- This is the code i have tried, i hope it helps to show you what i'm trying to do.
var registerStep1 = null;
var registerStep2 = null;
function getRegisterFiles(name) {
var request = $.ajax({
url: "/../files/Users/"+name+".ctp",
type: "GET",
dataType: "html",
error: function(jqXHR, textStatus) {
$('#pageLoading p').html('We have experienced a problem. Please try again later.');
return false;
},
success: function(msg) {
return msg;
}
});
}
registerStep1 = getRegisterFiles('registerStep1');
registerStep2 = getRegisterFiles('registerStep2');
var tempInterval = setInterval(function() {
if(registerStep1 != null && registerStep1 != false) {
if(registerStep2 != null && registerStep2 != false) {
clearInterval(tempInterval);
placeData(registerStep1);
}
}
}, 100);
function placeData(registerData) {
var tempTimer = 0;
tempTimer = setInterval(function() {
if(controlTimeUp != false) {
$('#pageWrap').html(registerData);
methodToFixLayout();
$('#pageWrap').fadeIn("slow");
$('#pageLoading').css("display","none")
clearInterval(tempTimer);
}
}, 10)
}