在关闭弹出窗口之前,相同的ajax调用了几次

I have more than 4 forms which has different name and id in my page and i create loop function to post every form with ajax.and loop work every form posting ın order. Problems:

1-gives me error like

"Uncaught TypeError: Cannot read property 'location' of null"

2-sometimes window.close work at first click(usually on local computer) sometimes not (usually at remoteserver) probably ajax calls interrupt closing

This is my script

<script name="ajax fonksiyonları" type="text/javascript">
            function validate(form){
            var  formID = form.id;
            var formDetails = $('#'+formID);
                $.ajax({
                    type: "POST",
                    url: 'ajax.php',
                    data: formDetails.serialize(),
                    success: function (data) {  
                        console.log(data);

                        window.opener.location.reload();
                        window.close()
                    },
                    error: function(jqXHR, text, error){
                    // Displaying if there are any errors
                    console.log(error);
                    }
                });
            return false;
        }
            function submitAll(){
                    for(var i=0, n=document.forms.length; i<n; i++){
                        validate(document.forms[i]);
                    }
                }

This is ajax.php

FUNCTION mysql_update_array($table, $data, $id_field, $id_value) {


 $data=data_cleaner($data);
 FOREACH ($data AS $field=>$value) {
    $fields[] = SPRINTF("`%s` = '%s'", $field, MYSQL_REAL_ESCAPE_STRING($value));
 }
 $field_list = JOIN(',', $fields);
 $query = SPRINTF("UPDATE `%s` SET %s WHERE `%s` = %s", $table, $field_list, $id_field, INTVAL($id_value));
 if( mysql_query($query) ) { 
    return array( "mysql_error" => false,
                  "mysql_insert_id" => mysql_insert_id(),
                  "mysql_affected_rows" => mysql_affected_rows(),
                  "mysql_info" => mysql_info()
                );
} else {
    return array( "mysql_error" => mysql_error() );
    }
}

if (isset($_POST['hupdate'])) {
    $result=mysql_update_array("customers", $_POST, "c_id", $_POST['c_id']);

}