【发布时间】:2019-05-26 09:11:42
【问题描述】:
我使用 django 频道在我的项目中实现即时消息应用程序。消息框不占用整个屏幕,所以我尝试使用 ajax 来实现它。我面临的问题是,在我的 ajax url 字段中以http://locahost 开头。我不想要这个,因为我使用带有 ws://
的 ASGI 和 django 频道我尝试在网址前加上“/”
var wsStart = 'ws://';
if (loc.protocol == 'https:'){
wsStart ='wss://';
}
var endpoint = wsStart + loc.host;
$.ajax({
type: 'POST',
url:"/"+endpoint+"/messages/"+username+"/",
data: {
'username': username,
csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]').val()
},
success: function (res, status) {
console.log("RESOPONSE",res);
},
error: function (res) {
console.log(res.status);
}
});
我希望 url 是 ws://localhost:8000/messages/
我现在得到的是
http://localhost:8000/ws://localhost:8000/messages/mohitharshan123/
【问题讨论】:
标签: ajax django django-channels