-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

3
  • 2
    What is not working? Any errors? Commented Feb 24, 2010 at 21:55
  • You are missing ); for $.post(. Is this code correct? Commented Feb 24, 2010 at 21:57
  • I dont get any errors.. How "format" my code? Commented Feb 24, 2010 at 21:59

1 Answer 1

2

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();
        }
    }});
}
Sign up to request clarification or add additional context in comments.

3 Comments

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.
What editor are you using? Any decent text editor will help you match parens/braces and help you with your indentation as well.
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").

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.