当前位置: 首页 > 工具软件 > AjaxUpload > 使用案例 >

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

尹钱青
2023-12-01
我们使用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上传失败!请核对列名');
				}
			}
		});
	},


 类似资料: