public void ProcessRequest(HttpContext context)
{
string result = "";
result = context.Request["path"];
string[] arry = result.Split('|');
string sourcePath = arry[0];
string destPath = arry[1]; try
{
System.IO.File.Copy(sourcePath, destPath);
result = "是";
}
catch (Exception)
{
result = "否";
}
context.Response.ContentType = "text/plain";
context.Response.Write(result);
}
function cpic()
{
debugger;
var filename = $("#fileUp1").val();
var date = new Date();
var newfullname = "Images/Bowser/"+ date.getFullYear()+date.getMonth()+date.getDay()+date.getHours()+date.getMinutes()+date.getSeconds()+date.getMilliseconds()+".jpg";
var aaa = filename+"|"+newfullname
$.post("ShowLocalPic.aspx",{"path" : aaa},function(data){
var sx = data;
alert(sx);
});
}
<form id="form1" runat="server">
<div>
<asp:FileUpload ID="fileUp1" runat="server" onchange="cpic()" />
<img id="img1" alt="" src="" class="img" />
</div>
</form>
var sx = data;
alert(sx);
});
response.end();
代码中加入,然后试试看。
我在ashx里面设了断点
根本没有执行到ashx文件里
弹出的是:error
$.ajax({
type: "POST",
url: "Default.aspx",
beforeSend: function(){
$("#div1").show();
},
success: function(msg){
alert( "Data Saved: " + msg );
},
error:function(e){
debugger;
alert(e.statusText);
}
});弹出的是:Not Found
怀疑你的url路径不对 看是不是正确,url:encodeURI(""),
原因没找到。重新建个网站,把代码copy过去,没改动过,又能进去ashx文件
不知道神马原因