我有一个图像列表,每个图像都有不同的ID.当用户点击特定<img>的"删除"按钮后,我想删除它,<img>并从服务器中删除图像文件.我有以下ajax调用,它将实现此目的.
$(document).ready(function () {
$("img").click(function () {
var img_id = $(this).attr("id");
var imagefile = img_id;
img_id = "#" + img_id;
$("button").click(function () { // delete button
$("#image " + img_id).remove();
$("button").unbind();
$.ajax({
type: "POST",
url: "deleteimage.php",
data: imagefile,
success: function(response) {
// do something
}
});
});
});
Run Code Online (Sandbox Code Playgroud)
在删除文件之前,我需要知道图像ID.所以我将它传递给变量然后将其发送到以下php文件.
<?php
include('config.php');
if(isset($_POST['imagefile']))
{
$imagefile = $_POST['imagefile'];
$imagepath = "Users/mp4_thumbnails-".$imagefile.".jpg";
unlink($imagepath);
}
?>
Run Code Online (Sandbox Code Playgroud)
可悲的是,这不起作用.这是我第一次尝试ajax调用.任何输入将不胜感激.
我有这个多步骤表格,我想验证(以确保指定正确格式的视频文件,并填写所有必填字段).我想使用jquery.validate插件来实现这一点.
问题是在我添加此验证代码之前,"上传"按钮工作正常.我相信我的代码出了问题导致"上传"按钮停止工作.我在这里包括一个小提琴:http://jsfiddle.net/NZr4n/
我相信这是导致错误的部分.有人可以帮忙吗?
$('#msform').validate({
rules: {
videoFile: {
required: true,
extension:'mov|mp4|mpeg|wmv'
}
videoTitle: {
required: true,
}
videoDescription: {
required: true,
}
},
messages: {
videoFile: "Please specify a file",
videoTitle: "Title is required"
videoDescription: "Description is required"
}
});
if ((!$('#msform').valid()) {
return false;
}
Run Code Online (Sandbox Code Playgroud)