数据是:..下面的行是否正确?我想将表单数据AND csrf标记发布到Django视图函数.
$('#file-upload').on('change',function () { var currentpath = window.location.pathname; var formData = new FormData($('form')[0]); $.ajax({ url: currentpath,//server script to process data type: 'POST',data: {formData,'csrfmiddlewaretoken': '{{ csrf_token }}'},cache: false,contentType: false,processData: false }); });@H_502_3@
解决方法
您必须将您的参数添加到FormData对象(使用
append)并始终将formdata对象单独作为data属性传递.
$('#id_image').on('change',function () { var currentpath = window.location.pathname; var formData = new FormData($('form')[0]); formData.append('csrfmiddlewaretoken','{{ csrf_token }}'); $.ajax({ url: currentpath,data: formData,processData: false }); });@H_502_3@