jquery ajax anonymous function when trying to pass form data -


i trying pass input file field through jquery ajax , getting anonymous function in chrome inspector console says because of line in script: $.ajax({

heres code run after have

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>   $("#sendcoverimageform").click(function(e){           e.preventdefault()           var mform = $("#sendformone").serialize()           $.ajax({               type: "post",               url: "{% url 'ajax_coverimage' %}",               data: mform,               success: function(data){                   console.log(data)                  $("#coverimagemodal").modal("hide");               },               error: function(data){                 var obj = data.responsejson                 $("#modalmessage").html("<p style='color:red;'>" + obj + "</p>")               },            });         }); 

if run script before

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> 

in console uncaught referenceerror: $ not defined - relating top line on script. run script , works , puts file model page renders "success <filename>" in dom rather console.

i'm noob jquery gladly recieved!

the $() equivalent jquery object jquery(), wich in both cases treat statements between parentheses in jquery function scope.
explains why script raise uncaught referenceerror before include jquery src, since $ sign isn't defined yet.

as musa said, shuold use formdata object, should keep in mind in ie it's supported ie10+, can use plugin support older browsers amount of code you'll writing support them unpleasant people starting out in javascript world should learn how afterwards, see filedropjs example.

here's tutorial using formdata (don't mind php).
hope helps!


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -