【问题标题】:exit from parent function according to ajax success callback return value根据ajax成功回调返回值退出父函数
【发布时间】:2014-12-29 06:11:55
【问题描述】:
//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 请求上传了该文件 如果文件已经存在ajax成功回调返回值data['doc_name'] = 'invalid'

如果文件已经存在if(data['doc_name'] == 'invalid')我想停止上传过程(想退出主上传功能)

【问题讨论】:

  • return false; 不工作???

标签: php jquery ajax


【解决方案1】:

你可以试试这个:如果你的 ajax 返回无效则显示错误信息,否则上传文件。

success:function(data)
 {
       //check file alreay exists
       if(data['doc_name'] != 'invalid')
       {
             //file uploading code
       }
       else
       {
            // Display your error message.
       }
 },

【讨论】:

  • 请在您的代码示例前添加一些描述
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-10
  • 2014-03-27
  • 1970-01-01
  • 1970-01-01
  • 2015-06-29
相关资源
最近更新 更多