Last active
July 6, 2020 00:27
-
-
Save hcosta/2fc16ecea0a916930fa8559508d50038 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var send = document.getElementById("send"); | |
send.addEventListener("click", function(){ | |
var content = encodeURIComponent(document.getElementById("content").value); // & | |
if (content.length > 0){ | |
const url = "{% url 'messenger:add' thread.pk %}" + "?content="+content; | |
fetch(url, {'credentials':'include'}).then(response => response.json()).then(function(data){ | |
// Si el mensaje se ha creado correctamente... | |
if (data.created) { | |
// Aquí iría el código de creación del mensaje dinámicamente | |
} else { | |
// Si algo ha ido mal podemos debugear en la consola del inspector | |
console.log("Algo ha fallado y el mensaje no se ha podido añadir.") | |
} | |
}) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment