急!!jqueryAjax上传文件问题

wj63558595 2010-06-24 09:13:12
莫名其妙。。。文件上传成功了,文件在服务端的相应目录生成了,但是没有运行success中的方法。见代码

index.jsp -- 页面
<script>

//上传文件
function fileSub(){
var filePath = $("#filePath").val();

$.ajaxFileUpload(
{
url:'billfile_upload.jsp',
secureuri:false,
fileElementId:'filePath',
asynchronous:true,
dataType: 'json',
success: function (data){//没有运行下面的方法
alert("上传成功1111111111");

},
error:function(xml) {//却运行error中,并且alert中的信息为[object].[object]
alert(xml);
}
}
);
return false;
}
</script>

<form enctype="MULTIPART/FORM-DATA" name="upload" id="upload">
<tr>
<td width="30%">选择对账单:</td>
<td width="70%">
<input type="file" name="filePath" id="filePath"/>
<input type="button" name="fsub" id="fsub" onclick="return fileSub();" value="上传附件" style="width:80px"/>
</td>
</tr>
</form>


billfile_upload.jsp -- 文件上传处理jsp
String path = request.getContextPath();
String para = null;
FileHttpServletRequest req = FileRequestHandler.fileParse(request);
for (Iterator it = req.getParameterMap().entrySet().iterator(); it
.hasNext();) {
Entry en = (Entry) it.next();
para = (String) en.getKey();
}
FileItem item = req.getFileParameter(para);

String filePath = item.getName();
String extFile = filePath.substring(filePath.lastIndexOf("."));

String fname = Long.toString(new Date().getTime());
String dir = "..//webapps//" + path + "//UP//"
+ fname + extFile;
try{
item.write(new File(dir));//文件写入成功
out.print(fname + extFile);//此句正确执行,并且返回有值
} catch(Exception e) {
e.printStackTrace();
out.print("0");
}
...全文
147 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wj63558595 2010-06-24
  • 打赏
  • 举报
回复
没错!是json格式问题!
小湘eeeee 2010-06-24
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 wqkjj 的回复:]

dataType: 'json',

返回数据格式不对,导致解析失败了吧
[/Quote]
wqkjj 2010-06-24
  • 打赏
  • 举报
回复
dataType: 'json',

返回数据格式不对,导致解析失败了吧
closewbq 2010-06-24
  • 打赏
  • 举报
回复

success: function(data, status)
{
if(typeof(data.error) != 'undefined')
{
if(data.error!= '')
{
alert(data.error);
}else
{
alert(data.msg);
}
}

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧