62,241
社区成员




$(function(){
$('#ShowUpPhoto').change(function(){
upload();
});
});
function upload(){
$.ajaxFileUpload(
{
url : '/Member/ajaxUpload.aspx?random=' + Math.random(),
secureuri : false,
fileElementId : 'ShowUpPhoto',
dataType : 'json',
success: function (data, status)
{
if(data.status == 'success')
{
$('#MemberPicUrl').val(data.msg.Origin);
alert(data.msg.Origin);
}
else
{
alert(data.msg);
}
},
error: function (data, status, e)
{
alert(data.msg);
alert(status);
alert(e);
}
});
$('#ShowUpPhoto').change(function(){
upload();
});
}
function updateUser(showID){
upload();
var name=$("#ShowUpName").val();
var title=$("#ShowUpTitle").val();
var email=$("#ShowUpEmail").val();
var com=$("#ShowUpCom").val();
var url=$("#MemberPicUrl").val();//这个url无论如何都是undefined的啊啊啊啊啊啊啊啊!!!
$.ajax({
url: 'Ajax/Handler.ashx',
data: "action=UpdateUser&id="+showID+"&name="+name+"&title="+title+"&email="+email+"&com="+com+"&url="+url,
type: 'post',
success: function(response){
location.reload();
}
});
}
HttpFileCollection files = Request.Files;
if (files != null && files.Count > 0)
{
HttpPostedFile file = files[0];
string uploadpath = "";
string msg = "";
Random rd = new Random();
uploadpath = string.Format("/UserPhoto/{0}-{1}/", DateTime.Now.ToString("d").Replace("/", "-"), rd.Next().ToString());
uploadpath = uploadpath.Replace("//", "/");
string fileuploadpath = Server.MapPath(uploadpath + "\\");
if (!Directory.Exists(fileuploadpath))
{
Directory.CreateDirectory(fileuploadpath);
}
if (file.FileName.Length > 0)
{
string ext = Path.GetExtension(file.FileName).ToLower();
if (ext != ".jpg" && ext != ".jepg" && ext != ".bmp" && ext != ".gif" && ext != ".png")
throw new Exception("只能上传jpg,bmp,gif,png格式的图片");
int fileSize = file.ContentLength;
if (fileSize > 2097152)
throw new Exception("上传图片最大为2M,上传失败");
string fileName = file.FileName;
fileName = string.Format("{0}-{1}-{2}", DateTime.Now.ToString("d").Replace("/", "-"), rd.Next().ToString(), fileName);
try
{
file.SaveAs(fileuploadpath + fileName);
msg = uploadpath + fileName;
Response.Write("{status:'success',msg:{Origin:'" + msg + "'}}");
//这里的msg的值大致如:/UserPhoto/2012-5-14-800087287/2012-5-14-1876285310-未命名.jpg
}
catch (Exception ex)
{
Response.Write(@"{
status : 'error',
msg : '" + ex.Message + @"'
}");
Response.End();
}
}
}
}
}
uploadHttpData: function( r, type ) {
var data = !type;
data = type == "xml" || data ? r.responseXML : r.responseText;
// If the type is "script", eval it in global context
if ( type == "script" )
jQuery.globalEval( data );
// Get the JavaScript object, if JSON is used.
if ( type == "json" )
eval( "data = " + data );
// evaluate scripts within html
if ( type == "html" )
jQuery("<div>").html(data).evalScripts();
return data;
}
Response.Clear();
Response.Write("{status:'200',success:true,msg:'"+msg +"'}");
Response.End();
Response.Clear();
Response.Write("{status:'200',success:true,msg:'"+msg +"'}");
Response.End();
Response.Write("{status:'200',success:true,msg:'"+msg +"'}");
Response.Write("{\"status\":\"success\",\"msg\":{\"Origin\":\"" + msg + "\"}}");