Skip to content

Instantly share code, notes, and snippets.

@dhbradshaw
Created April 6, 2015 20:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhbradshaw/237e82bba3290e8217a9 to your computer and use it in GitHub Desktop.
Save dhbradshaw/237e82bba3290e8217a9 to your computer and use it in GitHub Desktop.
django ajax
// uses jquery
$.ajax({
type: "POST",
url: "{% url 'attachment-object-coupling' project.slug %}",
data: {
attachment: attachments.attr("id"), // attachment instance_id
object: objects.attr("id"), // object instance_id
csrfmiddlewaretoken: '{{ csrf_token }}' // if not configured to include token in every post
},
success: function(data) {
updateDOM(data); // define elsewhere
},
error: function(jqXHR, textStatus, errorThrown) {
alert("Error, status = " + textStatus + ", " +
"error thrown: " + errorThrown
);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment