Firefox上的POST上的Ajax和500内部服务器错误

时间:2015-11-10 07:44:31

标签: javascript php jquery ajax codeigniter

我的网站是在Codeigniter中构建的。我的页面正在虚拟主机上运行。

我在以下函数的POST上收到Ajax和500内部服务器错误。我并不总是在所有计算机上都能得到它,而且在Firefox中更常见。这在Chrome中的个人计算机上从来就不是问题,但在另一台计算机上的Chrome中存在问题。它在手机上运行良好。这让我感到困惑,因为我知道这是服务器方面的问题。我检查了Apache日志,但没有找到任何内容。我怎么能追查这个问题?

以下是在领事中找到的:

https://www.mywebsite.com/site/index.php/appointments/ajax_get_available_days 
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
2https://www.mywebsite.com/site/index.php/appointments/ajax_get_available_hours 
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
POST
jquery.min.js:5     
https://www.mywebsite.com/site/index.php/appointments/ajax_get_available_hours 500 (Internal Server Error)
    send @ jquery.min.js:5
    m.extend.ajax @ jquery.min.js:5
    m.(anonymous function) @ jquery.min.js:5
    FrontendBook.getAvailableHours @ frontend_book.js:501
    (anonymous function) @ frontend_book.js:242
    m.event.dispatch @ jquery.min.js:4
    r.handle @ jquery.min.js:4

以下是有问题的功能:

public function ajax_get_available_days() {
    try {
        $interval_oneday =  new DateInterval( "P1D" );
        $today = new DateTime("today");
        $maxdays = (isset($_POST["timeframe"]) && is_int($_POST["timeframe"]))
                ? $_POST["timeframe"] 
                : 60;
        $available_days = array();
        for ($i = 0; $i < $maxdays; $i++) {
            $_POST["selected_date"] = $today->format('d-m-Y');
            ob_start();
            $this->ajax_get_available_hours();
            $available_hours_string = ob_get_contents();
            ob_end_clean(); 
            $available_hours = json_decode($available_hours_string);
            if (array_key_exists("exceptions", $available_hours)) {
                continue;
            } else {
                if (count($available_hours)>0) {
                    $available_days[] = $today->format('d-m-Y');
                }
            }
            $today->add($interval_oneday);
        }
        echo json_encode($available_days);
    } catch(Exception $exc) {
        echo json_encode(array(
            'exceptions' => array(exceptionToJavaScript($exc))
        ));
    }
}

public function ajax_get_available_hours() {
    $this->load->model('providers_model');
    $this->load->model('appointments_model');
    $this->load->model('settings_model');
    try {
        // If manage mode is TRUE then the following we should not consider the selected 
        // appointment when calculating the available time periods of the provider.
        $exclude_appointments = ($_POST['manage_mode'] === 'true') 
                ? array($_POST['appointment_id'])
                : array();    
        $empty_periods = $this->get_provider_available_time_periods($_POST['provider_id'], 
                $_POST['selected_date'], $exclude_appointments);
        // Calculate the available appointment hours for the given date. The empty spaces 
        // are broken down to 15 min and if the service fit in each quarter then a new 
        // available hour is added to the "$available_hours" array.
        $available_hours = array();
        foreach ($empty_periods as $period) {
            $start_hour = new DateTime($_POST['selected_date'] . ' ' . $period['start']);
            $end_hour = new DateTime($_POST['selected_date'] . ' ' . $period['end']);
            $minutes = $start_hour->format('i');
            if ($minutes % 30 != 0) {
                // Change the start hour of the current space in order to be
                // on of the following: 00, 15, 30, 45.
                if ($minutes < 30) {
                    $start_hour->setTime($start_hour->format('H'), 30);
                } else {
                    $start_hour->setTime($start_hour->format('H') + 1, 00);
                }
            }
            $current_hour = $start_hour;
            $diff = $current_hour->diff($end_hour);
            while (($diff->h * 60 + $diff->i) >= intval($_POST['service_duration'])) {
                $available_hours[] = $current_hour->format('h:i a');
                $current_hour->add(new DateInterval("PT60M"));
                $diff = $current_hour->diff($end_hour);
            }
        }
        // If the selected date is today, remove past hours. It is important 
        // include the timeout before booking that is set in the backoffice
        // the system. Normally we might want the customer to book an appointment
        // that is at least half or one hour from now. The setting is stored in 
        // minutes.
        if (date('m/d/Y', strtotime($_POST['selected_date'])) == date('m/d/Y')) {
            if ($_POST['manage_mode'] === 'true') {
                $book_advance_timeout = 0;
            } else {
                $book_advance_timeout = $this->settings_model->get_setting('book_advance_timeout');
            }
            foreach($available_hours as $index => $value) {
                $available_hour = strtotime($value);
                $current_hour = strtotime('+' . $book_advance_timeout . ' minutes', strtotime('now'));
                if ($available_hour <= $current_hour) {
                    unset($available_hours[$index]);
                }
            }
        }
        $available_hours = array_values($available_hours);
        //sort($available_hours, SORT_STRING );
        usort($available_hours, function($a, $b) {
           return (strtotime($a) > strtotime($b));
        });
        $available_hours = array_values($available_hours);
        echo json_encode($available_hours);

    } catch(Exception $exc) {
        echo json_encode(array(
            'exceptions' => array(exceptionToJavaScript($exc))
        ));
    }
}

AJAX请求:

    // Make ajax post request and get the available hours.
    var ajaxurl = GlobalVariables.baseUrl + '/index.php/appointments/ajax_get_available_days';
    jQuery.post(ajaxurl, postData, function(response) {
        ///////////////////////////////////////////////////////////////
        console.log('Get Available Days JSON Response:', response);
        ///////////////////////////////////////////////////////////////

        if (!GeneralFunctions.handleAjaxExceptions(response)) return;

        // The response contains the available days for the selected provider, 
        // service and timeframe. save that info in the timepicker and refresh it.
        $('#select-date').datepicker("option","availableDays", response);
        $('#select-date').datepicker("option","disabled", false);
        $('#select-date').datepicker("refresh");

    }, 'json');

并且。 。

    // Make ajax post request and get the available hours.
    var ajaxurl = GlobalVariables.baseUrl + '/index.php/appointments/ajax_get_available_hours';
    $.post(ajaxurl, postData, function(response) {
        ///////////////////////////////////////////////////////////////
        console.log('Get Available Hours JSON Response:', response);
        ///////////////////////////////////////////////////////////////

        if (!GeneralFunctions.handleAjaxExceptions(response)) return;

        // The response contains the available hours for the selected provider and
        // service. Fill the available hours div with response data. 
        if (response.length > 0) {
            var currColumn = 1;
            $('#available-hours').html('<div style="width:80px; float:left;"></div>');

            $.each(response, function(index, availableHour) {
                if ((currColumn * 10) < (index + 1)) {
                    currColumn++;
                    $('#available-hours').append('<div style="width:80px; float:left;"></div>');
                }

                $('#available-hours div:eq(' + (currColumn - 1) + ')').append(
                        '<span class="available-hour">' + availableHour + '</span><br/>');
            });

            if (FrontendBook.manageMode) {
                // Set the appointment's start time as the default selection.
                $('.available-hour').removeClass('selected-hour');
                $('.available-hour').filter(function() {
                    return $(this).text() === Date.parseExact(
                            GlobalVariables.appointmentData['start_datetime'],
                             'yyyy-MM-dd HH:mm:ss').toString('hh:mm tt');
                }).addClass('selected-hour');
            } else {
                // Set the first available hour as the default selection.
                $('.available-hour:eq(0)').addClass('selected-hour');
            }

            FrontendBook.updateConfirmFrame();

        } else {
            $('#available-hours').text(EALang['no_available_hours']);
        }
    }, 'json');

1 个答案:

答案 0 :(得分:0)

好的,问题是ssl。在不同的浏览器和机器中,个人通过http访问该站点而不是https。就这些。所以只需要一个简单的重定向。