views:

51

answers:

1
function checkSession(){
    $.ajax({url: "session.php", success: function(data){
         if( data == 1){
             var postFilen = 'msg.php';
             $.post(postFilen, function(data){
                 $("#msg").html(data).find("#message2").fadeIn("slow")
            }
         } else {
             $('#message2').hide();
         }
    }});
// setInterval('checkSession()',1000);
}

Basically, this is checking if data is 1 in session.php, and if it is, it should run msg.php´s div #message2 in #msg

+2  A: 

If you formatted your code more logically it would be clearer what your intentions were with this.

In your $.post() call, you close the curly brace on the function, but you don't close the $.post() paren.

Replace:

$.post(postFilen, function(data){
    $("#msg").html(data).find("#message2").fadeIn("slow")
}

with:

$.post(postFilen, function(data){
    $("#msg").html(data).find("#message2").fadeIn("slow");
});

Edit: This is what I mean by properly format:

function checkSession() {
    $.ajax({url: "session.php", success: function(data){
        if(data == 1) {
            var postFilen = 'msg.php';
            $.post(postFilen, function(data){
                $("#msg").html(data).find("#message2").fadeIn("slow");
            });
        } else {
            $('#message2').hide();
        }
    }});
}
Skilldrick
How do i format it? (to next time)
Karem
Every time you open a new curly brace, you should indent the following code. That way it's obvious that the code is 'inside' the curly braces.
Skilldrick
What editor are you using? Any decent text editor will help you match parens/braces and help you with your indentation as well.
Skilldrick
Another thing to look out for is missing semicolons. Although you can sometimes leave them out, it's always best to use them (e.g. after `fadeIn("slow")`.
Skilldrick