You still to put this code inside some sort of event handling function if your <script type='text/javascript'>
is not at the bottom of your <body>
. Try something like:
if($('#name')){
$('#usernameLoading').show();
$.post('check', {name: $('#name').val(), platform: $('#platform').val()}, function(response){
$('#usernameResult').fadeOut();
setTimeout(function(){
//need your usernameResult and response to be dealt with here
}, 400);
});
return false;
}
You should notice I changed your executed function that you passed into setTimeout()
. You cannot send an executed function into a parameter like that, unless you want it to execute on the spot. You could, however, create your finishAjax
method then pass it without a parameter like:
setTimeout(finishAjax, 400);
Unfortunately, setTimeout()
does not have an argument which you could pass a function argument to. To understand what I'm talking about review the following:
function lameFunc(func, funcArg){
return func(funcArg);
}
function lameQuote(q){
return q;
}
var whatever = lameFunc(lameQuote, 'var whatever is now this String');
That was an example of a function that passes an argument into another function. You could exchange lameQuote
with an Anonymous Function and still pass it an argument, like:
var someVar = lameFunc(function(arg){return arg;}, 'This String Will Go In arg and, therfore, someVar');
That's how setTimeout()
works internally, except that it does not take another argument that can be passed into your function, so It's more like:
function lameFunc(func){
return func();
}
Of course, there are obviously more differences, but this should teach you something.