0
//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) {} - main function upload file through ajax before upload check server has that file already uploaded through ajax request if file alreay exists ajax success call back return the value data['doc_name'] = 'invalid'

if file alredy exists if(data['doc_name'] == 'invalid') i want to stop uploading proccess (want to exit from main uploading function)

1
  • return false; not working??? Commented Dec 29, 2014 at 6:19

1 Answer 1

1

You can try this: If your ajax returns invalid then display error message otherwise upload file.

success:function(data)
 {
       //check file alreay exists
       if(data['doc_name'] != 'invalid')
       {
             //file uploading code
       }
       else
       {
            // Display your error message.
       }
 },
Sign up to request clarification or add additional context in comments.

1 Comment

Please, add some description before your code sample

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.