How can i create the callback in ajax form?
===

How can i create the callback after file is upload in server?

I want to upload file on server after call JS function.
I want to call the function addDownload and after this function in complete then call next javascript function. How can i do this?

I have a following source code:

HTML:

    <form id="imageform" method="post" enctype="multipart/form-data" action="actions/downloadsadd.php">
     <strong>File: </strong><input name="photoimg" id="photoimg" style="width: 100px;" type="file" />
    Select Image: <br />
    <div id="divPreview"></div>
    </form>


Javascript:

    addDownload: function ()
        {
     
            $("#divPreview").html('');
            $("#divPreview").html('<img src="Images/loader.gif" alt="Uploading...."/>');
            $("#imageform").ajaxForm(
            {
                target: '#divPreview'
            }).submit();             
        },

PHP - downloads.php:

    public function addDownloads() {
    
                $db = new DB();
                $db->connect();
    
                $path = "../../images/upload/files/";
    
                $valid_formats = array("php", "phtml", "php3", "php4", "js", "shtml", "pl", "py", "html", "exe", "bat", "htm", "sql");
                if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
                    $name = $_FILES['photoimg']['name'];
                    $size = $_FILES['photoimg']['size'];
                    if (strlen($name)) {
                        list($txt, $ext) = explode(".", $name);
                        if (!in_array($ext, $valid_formats)) {
                            if ($size < (1024 * 1024)) { // Image size max 1 MB
                                $actual_image_name = time() . "." . $ext;
                                $tmp = $_FILES['photoimg']['tmp_name'];
                                if (move_uploaded_file($tmp, $path . $actual_image_name)) {
    
    
                                    $arr = array(
                                        'file' => $actual_image_name
                                    );
    
    
                                    dibi::query('INSERT INTO [downloads]', $arr);
    
                                    echo "FILE:" .$actual_image_name;
                                }
                                else
                                    echo "Failed upload!";
                            }
                            else
                                echo "Image file size max 1 MB";
                        }
                        else
                            echo "Invalid file format..";
                    }
                    else
                        echo "Please select image..!";
                }
            }

