您的位置:首页 > Web前端 > JQuery

前台单击文件,jQuery删除后台相应真实的文件

2013-03-13 22:01 302 查看
Untitled Page

<script type="text/javascript">
$(function() {
$("body img").click(function() {
var name = $(this).attr("alt");
$.ajax({
url: "DeletePicsForm.aspx",
data: "picname="+name,
datatype: "json",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function(data, textStatus) {
alert(data.result);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest);
}
});
});
});
</script>

DeletePicsForm.aspx.cs:

protected void Page_Load(object sender, EventArgs e) {

if (Request["picname"] != null) {

Response.Clear();

Response.ContentType = "application/json";

String result = "success";

try {

File.Delete(Server.MapPath(@"\Images\")+Request["picname"].ToString());

}

catch (Exception ee) {

result = ee.Message;

}

Response.Write("{\"result\":\"" +result+ "\"}");

Response.End(); }

}

// $(funcition){
$("body img").click(function() {
var name = $(this).attr("alt");
$.ajax({
url: "DeletePicsForm.aspx",
data: "picname="+name,
datatype: "json",
type: "GET",
contentType: "application/json; charset=utf-8",
success: function(data, textStatus) {
alert(data.result);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest);
}
});
});

};
// ]]>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐