Passing Jquery value to PHP Script

bookings-dialog.php should not display HTML elements, it should return JSON encoded string.

add your result, and another for error, then you can handle error from jQuery

eg:

<?php
    require_once('deployment.php');
    require_once('bootstrp/all.inc.php');;
    require_once('models/sql.php');
    require_once('models/bookingdocket.php');

    $pdo = new SQL();
    $dbh = $pdo->connect(Database::$serverIP, Database::$serverPort, Database::$dbName, Database::$user, Database::$pass);

    try {
        $rowdata = $_POST['rowdata'];
        $query = ("SELECT * FROM tblbookings WHERE bookref = :bookref");
        $stmt = $dbh->prepare($query);
        $stmt->execute(array(':bookref' => $_POST['rowdata']));
        $row = $stmt->fetch(PDO::FETCH_BOTH);

        BookingDocket::set_bookref($row['bookref']);

        echo json_encode( array('bookref' => $row['bookref'], 'date' => $row['bookingdate'], 'error' => 'no') );
        $stmt->closeCursor();
    }
    catch (PDOException $pe) {
        die(json_encode(array("error" => "Error: " .$pe->getMessage(). " Query: ".$stmt->queryString)));
    }

    $dbh = null;

?>

also in your getGridRow check for error field:

success: function(data){
    if(typeof console != "undefined"){ console.log(data); } // this will prompt data in console
    if(data.error == 'no'){
        alert("IT WORKED!");
        $('.cp-booking-info').empty();
        $('#cp-bookings-dialog').append('<p class="pno-margin">Booking Date: '+data.date+'</p>');
        $("#cp-bookings-dialog").dialog({
            show: { effect: 'drop', direction: "up" },
            hide: 'slide',
            height: 625,
            width: 733,
            title: 'Booking Reference: - '+ data.bookref
        });
    } else {
        alert(data.error);
    }
}

I think the only thing to change is to replace :

title: 'Booking Reference: - '+ brData

By :

title: 'Booking Reference: - '+ data.bookref

brData looks undefined in the success callback


If you're asking for a JSON string, php should return that exact type. Javscript is waiting for the application/json content type.

So in php you need to add some header code:

require_once('deployment.php');
require_once('bootstrp/all.inc.php');
require_once('models/sql.php');
require_once('models/bookingdocket.php');

header('Content-Type: application/json');

$pdo = new SQL();
$dbh = $pdo->connect(Database::$serverIP, Database::$serverPort, Database::$dbName, Database::$user, Database::$pass);

try 
{
       $rowdata = $_POST['rowdata'];
       $query = ("SELECT * FROM tblbookings WHERE bookref = '$rowdata'");

       $stmt = $dbh->prepare($query);
       $stmt->execute();

       $row = $stmt->fetch(PDO::FETCH_BOTH);

      /* BookingDocket::set_id($row['id']); */
       BookingDocket::set_bookref($row['bookref']);
      /* BookingDocket::set_bookdate($row['bookingdate']);
       BookingDocket::set_returndate($row['returndate']);
       BookingDocket::set_journeytype($row['journeytype']);
       BookingDocket::set_passtel($row['passengertel']);
       BookingDocket::set_returndate($row['returndate']); */

       $booking_ref = BookingDocket::get_bookref();

       echo json_encode(array('bookref' => $booking_ref));

       $stmt->closeCursor();

}
catch (PDOException $pe)
{
    echo json_encode(array("Error: " .$pe->getMessage(). " Query: ".$stmt->queryString));
}
finally
{
    $dbh = null;
}