2010-02-24 157 views
0
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); 
} 

基本上,這是檢查是否有數據session.php文件1,如果是,就應該在#msgJavaScript/jQuery爲什麼這不起作用?

+2

什麼是不工作?任何錯誤? – 2010-02-24 21:55:03

+0

請格式化你的代碼 – 2010-02-24 21:55:20

+0

你缺少');我如何對其進行格式化(以''爲$。員額('這是正確的代碼,我 – 2010-02-24 21:57:38

回答

2

運行msg.php's#DIV消息2如果你更多的邏輯格式是你的代碼會更清楚你的意圖是什麼。

在您的$ .post()調用中,關閉函數上的大括號,但不關閉$ .post()paren。

替換:

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

有:

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

編輯:這就是我所說的正確格式:

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(); 
     } 
    }}); 
} 
+0

?。?下一次) – Karem 2010-02-24 22:01:38

+0

每次你打開一個新的大括號時,你應該縮進下面的代碼,這樣很明顯代碼是在大括號內「 – Skilldrick 2010-02-24 22:04:39

+0

你在使用什麼編輯器?任何像樣的文本編輯器都會幫助你匹配並且幫助你縮進, – Skilldrick 2010-02-24 22:06:12