fork download
  1. $(document).on("submit", "#post-form", function(e) {
  2. e.preventDefault();
  3. console.log("ajax is working!") // debug
  4. $.ajax({
  5. url : "/", // endpoint
  6. type : "POST",
  7. data : { url: $('#link-text').val(),
  8. csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken]').val() }, // data sent with the post request
  9.  
  10. // handle a successful response
  11. success : function(json) {
  12. $('#link-text').val(''); // removing the value from the input
  13. $('#results').html("easy");
  14. console.log(json); // log the returned json to the console
  15. console.log("success"); // another debug check
  16. },
  17.  
  18. // handle a non-successful response
  19. error : function(xhr,errmsg,err) {
  20. $('#results').html("<div class='alert-box alert radius' data-alert>We have encountered an error: "+errmsg+
  21. "<p>This operation is undoable"+" <a href='#' class='close'>&times;</a></div>"); // add error to the dom
  22. console.log(xhr.status + ": " + xhr.responseText); // more info about the error
  23. }
  24. });
  25. });
Runtime error #stdin #stdout #stderr 0.03s 16756KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.js:1:1 ReferenceError: $ is not defined
Stack:
  @prog.js:1:1