ajaxupload返回带有pre标签的数据处理方法

来源:互联网 发布:英国普利茅斯大学 知乎 编辑:程序博客网 时间:2024/05/29 13:56
我们使用ajaxupload插件上传文件时,有时返回的数据的是这样的:
<pre style="word-wrap: break-word; white-space: pre-wrap;">{"errCode":"","resCode":"0","resData":null}</pre>
这种数据怎么来处理的呢,那就用
var data = $.parseJSON(response.replace(/<.*?>/ig,""));

来处理。如下代码:

/**上传execl*/uploadExcel: function () {var button = $('#excel');var upload_url = commonAjax.defaultOption.cms_url + 'salary/uploadExcel.do';var upload_name = 'file';var loading =null;new AjaxUpload(button,{action: upload_url,name: upload_name,   //这相当于<input type = "file" name = "shanghaiFile"/>onSubmit : function(file, ext){if (ext && /^(xls|xlsx)$/.test(ext)){loading = layer.load(2, {shade: 0.1});} else {layer.msg('非excel格式,请重传!');return false;               }},onComplete: function(file, response){ //上传完毕后的操作layer.close(loading);console.log(response);//解析源码var data = $.parseJSON(response.replace(/<.*?>/ig,""));if (data.resCode==0) {layer.msg("上传成功!")salary.getSalaryList(1);} else {layer.msg('excel上传失败!请核对列名');}}});},


阅读全文
0 0
原创粉丝点击