0

I'm really struggling to get this working so any help would be much appreciated!

Basically I have a JQGRid that displays bookings with double click event as follows:

    ondblClickRow: function(rowid)
    {
        rowData = $("#bookings").getRowData(rowid);
                    var brData = rowData['bookref'];

        getGridRow(brData);
    },

This gets passed to getGridRow function:

function getGridRow(brData) {

    $.ajax({
      url: 'bookings-dialog.php',
      data: {'rowdata' : brData },
      dataType: 'json', //this is what we expect our returned data as
     error: function(){
                    alert("It failed");
                    $('#cp-div-error').html('');
                    $('#cp-div-error').append('<p>There was an error inserting the data, please try again later.</p>');
                    $('#cp-div-error').dialog('open');
             },
      success: function(data){
        //empty our dialog so we don't end up with duplicate content
        $('.cp-booking-info').empty();
        //we have told the browser to expect JSON back, no need to do any parsing
        //the date
        $('.cp-booking-info').append('<p class="pno-margin">Booking Date: '+data.bookref+'</p>');

        //now let's manipulate our dialog and open it.
        $("#cp-bookings-dialog").dialog({
          show: { effect: 'drop', direction: "up" },
          hide: 'slide',
          height: 625,
          width: 733,
          title: 'Booking Reference: - '+ brData
        });
      }

    });

And this is the bookings-dialog.php:

<?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 = '$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();


           return json_encode(array('bookref' => $booking_ref,
                                    )
                             );




        $stmt->closeCursor();

    }

    catch (PDOException $pe) {
        die("Error: " .$pe->getMessage(). " Query: ".$stmt->queryString);
    }

    $dbh = null;





?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Title Work</title>
<link rel="stylesheet" type="text/css" href="css/main.css" />
<link rel="stylesheet" type="text/css" href="css/styles.css" />
<link rel="stylesheet" type="text/css" href="lib/jq-ui/jquery-ui-1.8.16.custom.css" />
<link rel="stylesheet" type="text/css" href="lib/jq-grid/ui.jqgrid.css" />
<script type="text/javascript" src="scripts/js/utils/util-sha256.js"></script>
<script type="text/javascript" src="lib/jq-core/jquery-1.4.4.min.js" ></script>
<script type="text/javascript" src="lib/jq-ui/jquery-ui-1.8.16.custom.min.js" ></script>
<script type="text/javascript" src="lib/jq-grid/grid.locale-en.js"></script>
<script type="text/javascript" src="lib/jq-grid/jquery.jqGrid.min.js" ></script>
<script type="text/javascript" src="scripts/js/interface-datagrids.js"></script>
<script type="text/javascript" src="scripts/js/image-preload.js"></script>
<script type="text/javascript" src="scripts/js/general-interface.js" ></script>
<script type="text/javascript" src="scripts/js/general-controlpanel.js" ></script>
<script type="text/javascript" src="scripts/js/general-validation.js"></script>

</head>

<body>

<div id="cp-bookings-dialog">
  <div class="cp-tiles-wrapper-dlg">
    <div class="cp-booking-info left">
    </div>
  </div>
</div>


</body>
</html>

What I am trying to achieve is that when you double click a booking, the booking reference (e.g. BR12345) is passed to bookings-dialog.php and used in the the query (e.g. SELECT * FROM tblbookings WHERE bookref = '$rowdata'). I have been trying to use JSON to achieve this but at the moment when I double click a row, it is just failing at the moment and I am unsure why.

Any suggestions?

3
  • What exactly is failing? Apart from that you need to bind your variables, now you have an sql injection problem. Commented Aug 23, 2012 at 13:45
  • By default the type of request when you dont specify it in ajax is GET but in your .php script you're using POST. specify the type to post Commented Aug 23, 2012 at 13:46
  • The data being returned is coming back as 'unspecefied' any ideas? Commented Aug 23, 2012 at 19:06

2 Answers 2

2

Try:

   $.ajax({
      type: 'POST',  //ADD THIS .ajax defaults to GET and in the php you expect POST
      url: 'bookings-dialog.php',
      data: {'rowdata' : brData },
Sign up to request clarification or add additional context in comments.

Comments

1

The default HTTP type for AJAX calls is a GET. You should change to a POST.

$.ajax({
type:'POST',
...

http://api.jquery.com/jQuery.ajax/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.