2012-03-09 56 views
8

全部。我已经构建了一个简单的jQuery/PHP聊天程序,效果相当不错。不过,我想添加频道或房间等功能。理想情况下,我想使用聊天顶部的标签来管理用户所在的房间(只有2个)。我认为这将是一个简单的任务,并且我看到过类似的事情,但是当点击这些标签并且源代码无法正确加载时,我总是收到未捕获的异常错误。我会发布整个聊天系统的代码,因为我有一种感觉,问题可能在于此。未捕获的异常:jQuery UI选项卡:不匹配的片段标识符

jQuery的

page = { 
    getChat: function() { 
     $.ajax({ 
      url: 'game_src.php', 
      data: 'mode=getChat', 
      dataType: 'html', 
      cache: false, 
      success: function(res){ 
       $("#chatbox").html(res); 
      } 
     }); 
    } 
}; 

$("#submitmsg").click(function(){ 
    var clientmsg = $("#usermsg").val(); 
    $.ajax({ 
     url : 'game_src.php', 
     data: 'mode=chatSubmit&msg=' + encodeURIComponent(clientmsg) 
    }); 
    $("#usermsg").attr("value", ""); 
    return false; 
}); 

setInterval(page.getChat, 4000); 

$("#chatChannel").tabs({ 
    cookie: { expires: 1 }, 
}); 

聊天体

<?php 
if($user->data['user_id'] == ANONYMOUS) 
{ 

} 
else 
{ 
    ?> 
    <div id="chatChannel"> 
     <ul> 
      <li><a href="#global">Global</a></li> 
      <li><a href="#alli">Alliance</a></li> 
     </ul> 
    </div> 
    <form name="message" action=""> 
     <input name="usermsg" type="text" id="usermsg" size="25" /> 
     <input name="submitmsg" type="submit" id="submitmsg" value="Send" /> 
    </form> 
    <br /> 
    <?php 
} 
?> 
<div id="chatbox" style="border:1px solid black;background-color: rgba(255,255,255,0.3);height:400px;overflow:auto;"> 
    <div id="global"> 
    <?php 
    $chatMsgs = array(); 
    $limit = time()-86400; 

    $sql = 'SELECT COUNT(chat_id) as count FROM '.CHAT_TABLE.' WHERE chat_channel = 0 AND chat_time > '.$limit; 
    $result = $db->sql_query($sql); 
    $row = $db->sql_fetchrow($result); 
    $count = $row['count']; 

    if($count > 0) 
    { 
     $sql = 'SELECT * FROM '.CHAT_TABLE.' WHERE chat_channel = 0 AND chat_time > '.$limit.' ORDER BY chat_time DESC'; 
     $result = $db->sql_query($sql); 
     while($row = $db->sql_fetchrow($result)) 
     { 
      $chatMsgs[] = array(
       'chat_time' => $row['chat_time'], 
       'chat_msg' => $row['chat_msg'], 
       'chat_user' => $row['chat_user'], 
       'chat_channel' => $row['chat_channel'] 
      ); 
     } 

     foreach($chatMsgs as $msg) 
     { 
      $sql = 'SELECT username FROM '.USERS_TABLE.' WHERE user_id = '.$msg['chat_user']; 
      $result = $db->sql_query($sql); 
      $row = $db->sql_fetchrow($result); 
      $username = $row['username']; 

      echo '<div class="chatMsg" style="border-bottom:1px solid black;">'; 
      echo '<div class="chatUsr">'.$username.' says:</div>'; 
      echo '<div class="chatUsrMsg" style="float:left;">'.$msg['chat_msg'].'</div>'; 
      echo '<div class="chatMsgTime" style="float:right;">'.date("g:i a", $msg['chat_time']).'</div>'; 
      echo '</div>'; 
      echo '<br />'; 
      echo '<hr />'; 
     } 
    } 
    else 
    { 
     echo '<div class="chatMsg">Nothing is heard but the sound of crickets...</div>'; 
    } 
    ?> 
    </div> 
    <div id="alli"> 
    <?php 
    $chatMsgs = array(); 
    $limit = time()-86400; 

    $sql = 'SELECT COUNT(chat_id) as count FROM '.CHAT_TABLE.' WHERE chat_channel = 1 AND chat_time > '.$limit; 
    $result = $db->sql_query($sql); 
    $row = $db->sql_fetchrow($result); 
    $count = $row['count']; 

    if($count > 0) 
    { 
     $sql = 'SELECT * FROM '.CHAT_TABLE.' WHERE chat_channel = 1 AND chat_time > '.$limit.' ORDER BY chat_time DESC'; 
     $result = $db->sql_query($sql); 
     while($row = $db->sql_fetchrow($result)) 
     { 
      $chatMsgs[] = array(
       'chat_time' => $row['chat_time'], 
       'chat_msg' => $row['chat_msg'], 
       'chat_user' => $row['chat_user'], 
       'chat_channel' => $row['chat_channel'] 
      ); 
     } 

     foreach($chatMsgs as $msg) 
     { 
      $sql = 'SELECT username FROM '.USERS_TABLE.' WHERE user_id = '.$msg['chat_user']; 
      $result = $db->sql_query($sql); 
      $row = $db->sql_fetchrow($result); 
      $username = $row['username']; 

      echo '<div class="chatMsg" style="border-bottom:1px solid black;">'; 
      echo '<div class="chatUsr">'.$username.' says:</div>'; 
      echo '<div class="chatUsrMsg" style="float:left;">'.$msg['chat_msg'].'</div>'; 
      echo '<div class="chatMsgTime" style="float:right;">'.date("g:i a", $msg['chat_time']).'</div>'; 
      echo '</div>'; 
      echo '<br />'; 
      echo '<hr />'; 
        } 
    } 
    else 
    { 
     echo '<div class="chatMsg">Nothing is heard but the sound of crickets...</div>'; 
    } 
    ?> 
    </div> 
</div> 

我要去一个参数添加到getChat jQuery函数来来回切换,但与我有什么,我米卡住了。任何人都可以将我指向正确的方向吗?

回答

14

JQuery UI选项卡插件预计内容div与链接的ul位于相同的容器中。

对于您的情况,它预计内容div s在ul下的div id="chatChannel"右侧,但它们不在那里。

+0

在我的代码中,div正确地嵌套。问题在哪里呢? – softwareplay 2015-05-04 15:39:02

-3

我在将jQuery UI标签实现到jQuery Mobile应用程序时遇到了这个问题。 使用

的jquery 1.7.2

jquery的UI 1.8.2

jQuery Mobile的1.1。

Aparentry问题是jQuery用户界面和jQuery移动版本之间的兼容性的版本。

阅读埃夫里的bug报告和jQuery的库版本之间切换后,我找到了解决办法降级到1.0.1的jQuery Mobile的传统版本,它并没有使用jQuery UI选项卡组件冲突得到。

希望jQuery Mobile的开发人员修复此问题以便将来版本

相关问题