怎么用ajax+jquery实现删除文件夹中的图片
2个回答
2016-03-11 · 百度知道合伙人官方认证企业
育知同创教育
1【专注:Python+人工智能|Java大数据|HTML5培训】 2【免费提供名师直播课堂、公开课及视频教程】 3【地址:北京市昌平区三旗百汇物美大卖场2层,微信公众号:yuzhitc】
向TA提问
关注
展开全部
ajax结合jquery实现删除文件夹中的图片的例子:
<html xmlns="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>
<img src="Images/xiyangyang.jpg" alt="xiyangyang.jpg" />
</div>
</body>
</html>
删除的页面的代码如下:
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();
}
}
3、ajax操作后台的方法,用post传参:
$(function() {
$("body img").click(function() {
var name = $(this).attr("alt");
$.ajax({
url: "DeletePicsForm.aspx",
data: { picname: name },
datatype: "json",
type: "post",
success: function(data, textStatus) {
alert(data.result);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest);
}
});
});
});
<html xmlns="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>
<img src="Images/xiyangyang.jpg" alt="xiyangyang.jpg" />
</div>
</body>
</html>
删除的页面的代码如下:
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();
}
}
3、ajax操作后台的方法,用post传参:
$(function() {
$("body img").click(function() {
var name = $(this).attr("alt");
$.ajax({
url: "DeletePicsForm.aspx",
data: { picname: name },
datatype: "json",
type: "post",
success: function(data, textStatus) {
alert(data.result);
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest);
}
});
});
});
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询