jquery使用ajaxfileupload插件进行文件上传

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="${ctx}/js/jquery-1.2.1.js"></script>
<script type="text/javascript" src="${ctx}/js/ajaxfileupload.js"></script>
<script type="text/javascript">
function ajaxFileUpload()
{
    $("#loading")
    .ajaxStart(function(){
        $(this).show();
    })
    .ajaxComplete(function(){
        $(this).hide();
    });
var fileAdd = $("#fileToUpload").val();

    $.ajaxFileUpload
    (
        {
            url:'upload?fileAddress='+fileAdd+'&user_width=50&user_height=50',
            secureuri:false,
            fileElementId:'fileToUpload',
            dataType: 'jpeg',
            success: function (data, status)
            {

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

</script>
</head>
<body>
Ajax上传测试:
<form name="form" action="upload-store.action" method="POST" enctype="multipart/form-data" runat="server">
<input id="fileToUpload" type="file"  size="45" name="fileToUpload" />
<button id="buttonUpload" onclick="return ajaxFileUpload();">Upload</button>
</form>
<p/>
</body>
</html>

你可能感兴趣的:(html,jquery,Ajax,jsp)