python发送ajax请求_django ajax发送post请求

第一种:将csrf_token放在from表单里

function add_competion_goods() {

$.ajax({

url: "{% url 'add_competition_goods' %}",

type: "post",

datatype: "json",

data: $('#add_competition_goods_from').serialize(),//直接将from表单打包

success: function () {

$('#add_competition_modal').modal('hide');

alert('secces')

}

})

}

第二种:发送前添加头部信息

function submit_read_save_order_data() {

var excel_file = document.getelementbyid("order_excel").files;

var excel_file_size = excel_file[0]['size'];

console.log(excel_file_size);

if (excel_file_size > 0 & excel_file_size < 60000000) {

alert("已开始上传");

$('button#upload_data').attr('disabled', 'disabled');

{#console.log(excel_file_size);#}

var fd = new formdata();

fd.append('excels', excel_file[0]);

$.ajax({

url: "{%url 'read_save_order_data' %}",

type: "post",

datatype: "json",

data: fd,

processdata: false,// tell jquery not to process the data

contenttype: false,// tell jquery not to set contenttype

beforesend: function (xhr, setting) {

xhr.setrequestheader("x-csrftoken", "{{ csrf_token }}")

},

success: function (msg) {

alert(msg)

},

error: function (msg) {

alert(msg)

}

}

)

} else {

alert("文件为空,或大小超出60m,请检查")

}

}

希望与广大网友互动??

点此进行留言吧!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值