Skip to content

Instantly share code, notes, and snippets.

@hcosta
Last active July 6, 2020 00:27
Show Gist options
  • Save hcosta/2fc16ecea0a916930fa8559508d50038 to your computer and use it in GitHub Desktop.
Save hcosta/2fc16ecea0a916930fa8559508d50038 to your computer and use it in GitHub Desktop.
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