//this function will upload file through ajax
add: function (e, data) {
//before upload file check server has that file already uploaded
$.ajax(
{
type: "POST",
dataType:'json',
url:"../admin/cgi/file_check.php",
async:false,
data:{
filename : upload_filename,
docname : upload_docname,
userid : upload_userid,
},
success:function(data)
{
//check file alreay exists
if(data['doc_name'] == 'invalid')
{
// if file alreay exists want to stop upload process
//exit from main funtion
}
},
error:function(request,errorType,errorMessage)
{
alert ('error - '+errorType+'with message - '+errorMessage);
}
});
//file uploading code
}
add: function (e, data) {}
- 主要功能通过ajax上传文件
在上传之前,检查服务器已经通过ajax请求上传了该文件
如果文件alreay存在,则ajax成功回调返回值data['doc_name'] = 'invalid'
如果文件alredy存在if(data['doc_name'] == 'invalid')
我想停止上传进程(想要退出主上传功能)
答案 0 :(得分:1)
您可以尝试这样做:如果您的ajax返回无效,则显示错误消息,否则上传文件。
success:function(data)
{
//check file alreay exists
if(data['doc_name'] != 'invalid')
{
//file uploading code
}
else
{
// Display your error message.
}
},