我尝试使用技术Ajax将图像上传到服务器。 控制台输出错误:
POST http://localhost:4246/pr_with_div/pr_per.aspx 500(Interval server Error)
send
jQuery.extend.ajax
(anonymous function)
jQuery.event.dispatch
elemdata.handle
你能告诉我怎么修理它吗?
1)页面pos.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="pos.aspx.cs" Inherits="pos" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.ui/1.10.3/jquery-ui.min.js"></script>
<script language="javascript">
$(document).ready(function() {
$("#mainForm").submit(function (event) {
event.preventDefault();
var data = new FormData($('#mainForm')[0]);
$.ajax({
type: "POST",
url: "pr_per.aspx",
data: data,
contentType: false,
processData: false,
beforeSend: function () {
$('#loader').show();
}
})
});
});
</script>
</head>
<body>
<form id="mainForm" runat="server" enctype="multipart/form-data" >
<input type="file" id="myFile" name="myFile" />
<asp:Button runat="server" ID="btnUpload" Text="Upload" /><asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</form>
</body>
</html>
2)页面pr_per.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="pr_per.aspx.cs" Inherits="pr_per" %>
<%@ Import Namespace="System.IO" %>
<%
HttpPostedFile file = Request.Files["myFile"];
if (file != null && file.ContentLength > 0)
{
string fname = Path.GetFileName(file.FileName);
file.SaveAs(Server.MapPath(Path.Combine("~/img/", fname)));
}