同时我们需要了解相关的错误提示
1,SyntaxError: missing ; before statement错误
如果出现这个错误就需要检查url路径是否可以访问
2,SyntaxError: syntax error错误
如果出现这个错误就需要检查处理提交操作的PHP文件是否存在语法错误
3,SyntaxError: invalid property id错误
如果出现这个错误就需要检查属性ID是否存在
4,SyntaxError: missing } in XML expression错误
如果出现这个错误就需要检查文件域名称是否一致或不存在
5,其它自定义错误
大家可使用变量$error直接打印的方法检查各参数是否正确,比起上面这些无效的错误提示还是方便很多。
使用jQuery插件AjaxFileUpload实现无刷新上传文件非常实用,由于其简单易用,因些这个插件相比其它文件上传插件使用人数最多,非常值得推荐。
处理页面:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;public partial class web_ajax_FileUpload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
HttpFileCollection files = HttpContext.Current.Request.Files;
//if (files[0].ContentLength > 5)
//{
// Response.Write("{");
// Response.Write("msg:'" + files[0].FileName + "',");
// Response.Write("error:'文件上传失败'");
// Response.Write("}");
//}
//else
//{
// Response.Write("{");
// Response.Write("msg:'没有文件被上传',");
// Response.Write("error:'文件上传失败'");
// Response.Write("}");
//}
files[0].SaveAs("d:/adw.jpg");
Response.Write("{");
Response.Write("msg:'a',");
Response.Write("error:''");
Response.Write("}");
//Response.Write("{");
//Response.Write("msg:'gggn',");
//Response.Write("error:'aan'");
//Response.Write("}");
Response.End();
}
}
其它网友的补充:
页面代码:
<html>
<!– 引入相关的js文件,相对路径 –>
<script type=”text/javascript” src=”js/jquery.js”></script>
<script type=”text/javascript” src=”js/ajaxfileupload.js”></script>
<!– 执行上传文件操作的函数 –>
<script type=”text/javascript”>
function ajaxFileUpload(){










