Im using django channels for implementing instant messaging app in my project.The message box does not take up th entire screen ,so im trying to implement it using ajax.The problem im facing is that in my url field in the ajax is prepending with http://locahost .I dont want this since im using ASGI and django channels with ws://
I have tried prepending the url with a "/"
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);
}
});
I want the url to be ws://localhost:8000/messages/
what i get now is
http://localhost:8000/ws://localhost:8000/messages/mohitharshan123/