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(); }
}