上传图片取值
图片取值得做一个处理
//new一个新的FormData var imgData = new FormData(); var files = document.getElementById('FListImg'); var file = files.files[0];//files 不存在 imgData.append('file', file); imgData.append('jsonData'JSON.stringify({所需要穿的数值})),
在将要传得所有值都封装带一个封装包里。在将其传入后台
使用AJAX传值时 data为封装包 contentType设为不对其在进行转换格式 直接传到后台
$.ajax( { type: "POST", url: "NewsList.ashx?action=NewsAdd", data: imgData, contentType: false, dataType: "json", processData: false, async: false, cache: false, success: function (data) { debugger; if (data.state) { //提示并刷新页面 swal({ title: data.msg, //弹出框的title type: "success", //弹出框类型 showCancelButton: false,//是否显示取消按钮 timer: 1000, }, function (isConfirm) { window.location.href = data.url; } ); } else { swal({ title: data.msg, //弹出框的title type: "warning", //淡出框类型 showCancelButtun: false,//是否显示取消按钮 confirmButtonColor: "#DD6B55",//确定按钮颜色 confirmButtonText: "确定", //确定按钮上面的文档 closeOnConfirm: true, timer: 1000, }, function (isConfirm) { window.location.href = data.url; } ); } }, error: function () { swal({ title: "服务器异常", //弹出框的title type: "waring", //弹出框类型 showCancelButton: false, //是否显示取消按钮 confirmButtonColor: "#DD6B55",//确定按钮上面的文档 closeOnConfirm: true }); } })
让我们一起来学习C#吧~~~
浙公网安备 33010602011771号