Advertisement
Broatlas

Untitled

Mar 6th, 2018
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $("#floorplan-post").submit(function (event) {
  2.         //handles the post for the floorplan
  3.        event.preventDefault();
  4.        var eventId = $("#hidden_id").attr('name');
  5.        var formData = new FormData();
  6.        var img = $('#validatedCustomFile')[0].files[0];
  7.        formData.append('img',img);
  8.  
  9.  
  10.            //sends out into a token before the ajax request
  11.  
  12.        $.ajaxSetup({
  13.             beforeSend: function(xhr, settings) {
  14.                     xhr.setRequestHeader("X-CSRFToken", '{{ csrf_token }}');
  15.                     console.log("Sent csrf");
  16.             }
  17.         });
  18.  
  19.        $.ajax({
  20.         url: "{% url 'events:load_floorplan' %}",
  21.         method:'POST',
  22.         processData: false,
  23.         data: formData,
  24.         success: function(response){
  25.             console.log("finshed");
  26.  
  27.         },
  28.         error:function(data, textStatus, errorThrown){
  29.                 console.log("failed server side", errorThrown);
  30.             }
  31.        })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement