Note that there are some explanatory texts on larger screens.

plurals
  1. POcontent is not being dynamically added to jquery mobile dialog page prior to being opened atleast once
    primarykey
    data
    text
    <p>im using jquery mobile dialog pages as a chat box, so when a user sends a chat request to another user, and the receiving user is accepts the request, a new dialog page is dynamically created on both ends succesfully. The problem is, when one user sends the message to another user before the receiving user opens the dialog page, the content is not added to the page, but when the receiving user opens the page then the sender sends another message the message is added, if the receiving user closes the dialog page and the sender sends another message, when the receiver opens the dialog page, the new message is shown. This means the dialog page has to be opened atleast once in order for content to be dynamically added. Is there a way i can go around this problem</p> <p>SERVER SIDE CODE THAT RELAYS THE MESSAGE</p> <pre><code>function send_msg($clientID, $message) { global $Server; global $CLIENT; global $USERMAP; $me = $CLIENT[$clientID][2]; $logmsg = new SQLquery; $logmsg-&gt;db_query("INSERT INTO chat_messages (user_hash, chat_token, chat_message, send_to) VALUES (?, ?, ?, ?)", $me,$message-&gt;chat_token, $message-&gt;msg, $message-&gt;send_to_user ); if(isset($USERMAP[$message-&gt;send_to_user])) { $resp["action"]= "message"; $resp["chat_token"]= $message-&gt;chat_token; $resp["msg"] = $message-&gt;msg; $resp["user"]= $message-&gt;send_to_user; $resp["msuasa"] = "shitmananana"; var_dump($resp); var_dump($USERMAP[$message-&gt;send_to_user]); $Server-&gt;wsSend($USERMAP[$message-&gt;send_to_user], json_encode($resp)); } } </code></pre> <p>HERE IS HOW THE PAGE IS CREATED *NOTE * THE PAGE IS CLONED FROM A TEMPLATE: </p> <pre><code>function create_chat_page(user, chat_token) { var sel_id = "#" + user; $("#chat_page").clone().insertAfter("#chat_page").attr("id", chat_token).attr("data-chat_to", user).trigger("create"); var pic_thum = $(sel_id + " img").attr("src").substring(36); $("#" + chat_token + " .user_chat_icon").html("&lt;img src='../../photos/users/icons/icon_" + pic_thum + "'/&gt;"); $(sel_id + " h2").clone().addClass("user_chat_name").insertAfter("#" + chat_token + " .user_chat_icon"); } </code></pre> <p>CLIENT SIDE ON MESSAGE EVENT WHEN TO SORT OUT THE MESSAGES FROM THE SERVER</p> <pre><code>function chat_inc_sort(data) { switch (data.action) { case "message": sort_message(data); break; case "rec_req": process_req(data);/*********/ break; case "accept": accept_req(data); break; case "reject": reject_req(data); break; case "set_status": set_status(data.user, "online"); break; case "unset_status": set_status(data.user, "offline"); break; } } </code></pre> <p>THIS FUNCTION CALLS CALLS THE putMessage functio</p> <pre><code>function sort_message(data) { var d = new Date(); var ixesha = d.getHours().toString() + ":"+ d.getMinutes().toString(); putMessage(data.user.toString(), data.chat_token.toString(),data.msg.toString(),ixesha); } </code></pre> <p>AND THIS IS HOW MESSAGE RECEIVED ARE POPULATED ON THE SCREEN</p> <pre><code>function putMessage(user, chat_token, msg, time) { alert(time); var sel_id = "#" + chat_token; $(sel_id + " div .chat_box").append("&lt;div&gt;" + time + "&lt;p class='usr_txt'&gt;" + msg + "&lt;/p&gt;&lt;/div&gt;"); } </code></pre> <p>THIS IS THE CLONED TEMPLATE</p> <pre><code>&lt;div id="chat_page" class="chat_screen" data-role="page" data-theme="b" data-close-btn="none"&gt; &lt;div data-role="header" data-position="fixed"&gt; &lt;span class="user_chat_icon" data-inline="true" class="ui-btn-left"&gt;&lt;/span&gt; &lt;a href="#" data-inline="true" class="ui-btn-right"&gt;close&lt;/a&gt; &lt;/div&gt; &lt;div class="chat_box" data-role='content'&gt;&lt;/div&gt; &lt;div data-role="footer" data-position="fixed"&gt; &lt;textarea class="msg_box" data-inline="true" cols="30" rows="2" maxlength="500"&gt;&lt;/textarea&gt; &lt;a class="send_msg" data-role="button" data-inline="true" data-theme="a"&gt;send&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload