Click file at the front-end. jquery deletes the real files in the background, including two pages: one for displaying images and the other for transferring file names and then deleting the pages for real images. The specific code is as follows:
Showpics.htm:
<! 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>
<Title> untitled page </title>
<SCRIPT src = "JS/jquery-1.4.4.js" type = "text/JavaScript"> </SCRIPT>
<SCRIPT src = "JS/json2.js" type = "text/JavaScript"> </SCRIPT>
<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>
</Head>
<Body>
<Div>
</Div>
</Body>
</Html>
The code for deleting a page is as follows:
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 ();
}
}