JS中提交表单?<button type='submit' >提交</button>,不想用ajax重写put_challenge()方法
function put_challenge(){
c = layer.open({
type: 1,
area: ['242px', '185px'],
fixed: true,
title:"Put a New Challenge",
content:
"<div class='drag_upload'>"+
"<form method='post' enctype='multipart/form-data'>"+
"<input type='file' id='file' name='filename' class='file_cselectfile' />"+
"<button type='submit' >提交</button>"+
"</form>"+
"</div>"+
"<script>"+
"layui.use(['form','upload'],function(){"+
"var form = layui.form;var upload = layui.upload;"+
"upload.render({"+
"elem: '#upload_data_chall'"+
",url: 'upload.html' "+
",accept:'file'"+
",exts: 'txt'"+
",done: function(res){"+
"layer.msg('Success');"+
"console.log(res);"+
"close_upload();"+
"}"+
",error: function(){"+
"layer.msg('Submit Challenge Successfully.');"+
"close_upload();"+
"console.log(res)"+
"}"+
"});"+
"});"+
"</script>"
});
}
在网上搜遍了资料还是没有一个好的解决方法,直到看到!
@csrf_exempt
?结果成功了!
?真是踏破铁鞋无觅处得来全不费工夫!
|