We are using a form to submit the data and getting the response from our API the code below works fine -
if (0 == strlen($_POST['from_location'])) {
    $_response[] = 'Enter from location';
}
if (0 == strlen($_POST['to_location'])) {
    $_response[] = 'Enter to location';
}
try {
        $_fromDate=DateTime::createFromFormat('m/d/Y',$_POST['from_date']);
        $_toDate =  DateTime::createFromFormat('m/d/Y', $_POST['to_date']); 
        $_interval = $_fromDate->diff($_toDate); //Line 21 where error comes
        $_noOfDays = $_interval->format('%d');
}catch(Exception $e){
    $_response[] = $e->getMessage();
}
Corresponding JS code used in our HTML submit page is -
function testAjaxCall(formobj) {
                $.post(
                    formobj.action,
                    $(formobj).serialize(),
                    function (response, status, jqXhr) {
                        alert(response);
                    },
                    'html'
                );
            }
The above code works fine and gives us the response from API.
However, when we try to change the JS code to -
function testAjaxCall(formobj) {
                $.post(
                    formobj.action,
                    $(formobj).serialize(),
                    function (response, status, jqXhr) {
                        //alert(response);
                        location.href = 'hotel_search.php';
                    },
                    'html'
                );
            }
We get the following Notices and a fatal error the notices are removed by using isset for our input fields. The dates need to be send back in Y/m/d format as thats how we receive the response. I have already gone through the Stackoverflow and googled it as well however, none of the solutions are working for us.
Notice: Undefined index: from_location in /home/developeriq/public_html/doylesweb/hotel_search.php on line 11
Notice: Undefined index: to_location in /home/developeriq/public_html/doylesweb/hotel_search.php on line 14
Notice: Undefined index: from_date in /home/developeriq/public_html/doylesweb/hotel_search.php on line 19
Notice: Undefined index: to_date in /home/developeriq/public_html/doylesweb/hotel_search.php on line 20
Fatal error: Call to a member function diff() on a non-object in /home/developeriq/public_html/doylesweb/hotel_search.php on line 21
Can anyone please help and see what we are doing wrong.
Thanks
