var filterTypes="*"; function seeFile(path,id,file){ //alert("a"); //window.open("SeeFileServlet.do?path=" + path + "&id="+ id + "&fileName=" + file); popup("SeeFileServlet.do?path=" + path + "&id="+ id + "&fileName=" + file,'seefile'); } function modify(index,file){ if ($("#modify"+index).text()=="修改"){ $("#"+index+"1").html(""); $("#"+index+"3").html(""); $("#file"+index +"3").val($("#"+index+"3").html()); $("#modify"+index).text("提交"); } else { //alert(file); //alert($("#"+"file"+index+"1").val()); $.ajax({ type:"POST", url:"AjaxModifyFile.do", data:{ id:$("#file-id").val(), path:$("#file-path").val(), fileName:encodeURIComponent($("#"+"file"+index+"1").val()), fileType:$("#"+"file"+index+"3").val(), fileId:file}, success:function(data){ if ((data.substring(0,3))=="err") $("#errMsg").html(data); else $("#output1").html(data); } }) } } function submitFile(index){ } function remove(file){ //alert($("#id").val()); //alert($("#path").val()); //alert(file); $.ajax({ type:"POST", url:"AjaxRemoveFile.do", data:{id:$("#file-id").val(),path:$("#file-path").val(),file:encodeURIComponent(file)}, success:function(data){ if ((data.substring(0,3))=="err") $("#errMsg").html(data); else $("#output1").html(data); } }) } $(document).ready(function() { var options = { //target: '#output1', // 用服务器返回的数据 更新 id为output1的内容. beforeSubmit: showRequest, // 提交前 success: showResponse, // 提交后 //另外的一些属性: //url: url // 默认是form的action,如果写的话,会覆盖from的action. //type: type // 默认是form的method,如果写的话,会覆盖from的method.('get' or 'post'). //dataType: null // 'xml', 'script', or 'json' (接受服务端返回的类型.) //clearForm: true // 成功提交后,清除所有的表单元素的值. resetForm: true // 成功提交后,重置所有的表单元素的值. //由于某种原因,提交陷入无限等待之中,timeout参数就是用来限制请求的时间, //当请求大于3秒后,跳出请求. //timeout: 3000 }; //alert("=============") ; //'ajaxForm' 方式的表单 . $('#attach-form').ajaxForm(options); //或者 'ajaxSubmit' 方式的提交. //$('#myForm').submit(function() { // $(this).ajaxSubmit(options); // return false; //来阻止浏览器提交. //}); }); // 提交前 function showRequest(formData, jqForm, options) { //alert("====="); // formdata是数组对象,在这里,我们使用$.param()方法把他转化为字符串. var queryString = $.param(formData); //组装数据,插件会自动提交数据 //alert(queryString); //类似 : name=1&add=2 $name=$('#attach-form-file').val(); if ($name=="") { alert("请选择要上传的文件"); return false; } else { var len=$name.length; var start=$name.lastIndexOf("."); var type=$name.substring(start,len); if (filterTypes!="*"){ if (filterTypes.indexOf(type)==-1) { alert("文件格式"+filterTypes); return false; } } if (type==".exe" || type==".jsp" || type==".bat" ||type==".jar"){ alert("不允许的文件格式"); return false; } $("#errMsg").html("正在上传..."); return true; } } // 提交后 function showResponse(responseText, statusText) { if ((responseText.substring(0,3))=="err") $("#errMsg").html(responseText); else { $("#output1").html(responseText); $("#errMsg").html("正在上传...OK"); } }