这是我的php函数,它从数据库中获取聊天消息
function get_msg(){
$query_get = "SELECT * FROM chat WHERE chat_id = $user_id";
$run = $db->query($query_get);
$messages = Array();
while ($message = mysqli_fetch_assoc($run)) {
$msg_string = $message['msg'];
echo "$msg_string";
}
}
这里是JS函数,我想调用上面的php函数
function register_popup(id, name)
{
for(var iii = 0; iii < popups.length; iii++)
{
//already registered. Bring it to front.
if(id == popups[iii])
{
Array.remove(popups, iii);
popups.unshift(id);
calculate_popups();
return;
}
}
var msg_string = <?php echo json_encode($msg_string);?>
var element = '<div class="popup-box chat-popup" id="'+ id +'">';
element = element + '<div class="popup-head">';
element = element + '<div class="popup-head-left">'+ name + '</div>';
element = element + '<div class="popup-head-right"><a href="javascript:close_popup(\''+ id +'\');">✕</a></div>';
msg();
element = element + '<div style="clear: both"></div></div>';
element = element + '<div class="popup-messages">';
element = element + '<div class="incoming_mesg">
// **here i want to call the php function**
get_msg();
</div>';
element = element + '<div class="outgoing_mesg">Text area for outging message</div></div></div>';
document.getElementsByTagName("body")[0].innerHTML = document.getElementsByTagName("body")[0].innerHTML + element;
popups.unshift(id);
calculate_popups();
}