我已经使用 js 和 ajax 集成了 zulip api,问题是交换的消息不在真实的 tile 中所以请,如何使用 js 和 ajax 来收听实时事件 zulip,这是我的 js 代码
$("#post").click(function () {
var url = 'https://domain_name/api/v1/messages';
var content = $("#postButton").val();
$.ajax({
type: "post",
url: url,
data: {type: 'private', content: content, to: 'khalil@gmail.com'},
headers: {Authorization: getBasicAuthenticationToken(username,
password)},
})
});
$(function () {
var $msgs = $('#msgs');
$.ajax({
type: 'GET',
url: 'https://domain_name/api/v1/messages',
data: {num_before: 10, num_after: 1000, use_first_unread_anchor: true},
headers: {
"Authorization": getBasicAuthenticationToken(username, password)
},
success: function (msgs) {
/*console.log(msgs['messages'][0]['sender_email']);*/
$.each(msgs.messages, function (i, msg) {
$msgs.append('<li>' + msg.content + '</li>');
$msgs.append('<li>' + msg.sender_email + '</li>');
var who = msg.sender_email;
insertChat('<p>' + who + '</p>', '<p>' + msg.content +'</p>',0)
});
}
});
});