0

我有一个带有 OndblClickRow 函数的 JQGrid,如下所示:

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



        getGridRow(brData);

        //$("#cp-bookings-dialog").dialog({ hide: 'slide', height: 625, width: 733, title: 'Booking Reference: - '+ brData});
    },

这被传递给以下函数:

function getGridRow(brData) {

    $.post("bookings-dialog.php", { 'rowdata': brData } );
               $("#cp-bookings-dialog").load('bookings-dialog.php').dialog({ show: "slide", hide: 'slide', height: 625, width: 733, title: 'Booking Reference: - '+ brData});
    ,

加载 bookings.dialog.php 页面:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Title</title>
<?php

set_include_path($_SERVER['DOCUMENT_ROOT'] . "/onlinebookingv4/scripts/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']);



        $stmt->closeCursor();

    }

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

    $dbh = null;





?>
</head>

<body>
<div class="cp-tiles-wrapper-dlg">

<div class="cp-booking-info left">

    <p class="pno-margin">Booking Date: &nbsp;<strong>Booking Reference is = <? echo BookingDocket::get_bookref(); ?></strong></p>
    <p class="pno-margin">Query =  &nbsp;<strong><? echo $query; ?></strong></p>
    <p class="pno-margin">Journey: &nbsp;<strong></strong></p>
    <p class="pno-margin">Passenger Tel: &nbsp;<strong></strong></p>
    <p class="pno-margin">E-mail: &nbsp;<strong></strong></p>

</div>

</div>
</body>
</html>

我要做的是传递“brData”,这是对 bookings-dialog.php 的预订参考,以便我可以通过预订参考从数据库中选择所有预订。

目前,当我双击一行时,在萤火虫控制台中我得到以下信息:

POST bookings-dialog.php 显示SELECT * FROM tblbookings WHERE bookref = 'BR1278'哪个是正确的

但它也显示:

获取正在显示的 bookings-dialog.phpSELECT * FROM tblbookings WHERE bookref = ''

对我来说,这似乎被某种方式覆盖了,我可能错了。

有人知道我怎样才能让它工作吗?

4

1 回答 1

0

我们不想发回 HTML,我们想发回 JSON 之类的东西。我们的#cp-bookings-dialog元素应该有一个看起来像 -> 的 HTML 结构

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

然后我们将数据发送到服务器。您现有的代码实际上很好,我的评论假设了不同类型的操作。

$.post("bookings-dialog.php", { 'rowdata': brData } );

这是我必须做出假设的地方。在你完成你set_var($_POST['var'])BookingDocket课程之后,我们应该只返回一个 JSON 编码的键值对数组,以便在我们的浏览器中解析,并用于更新对话框中的信息。

//for example, only showing the last two...
BookingDocket::set_passtel($row['passengertel']);
BookingDocket::set_returndate($row['returndate']);

//create a scope of variables to prepare and return
$booking_date = BookingDocket::get_bookref();
//query is already set, omitting it.
//making assumptions about data I cannot see
$journey = BookingDocket::get_journey();
$pass_tel = BookingDocket::get_tel();
$email = BookingDocket::get_email();

//formatting here is for example and not live usage
return json_encode(array("date" => $booking_data, 
                         "query" => $query, 
                         "journey" => $journey, 
                         "pass_tel" => $pass_tel, 
                         "email" => $email
                         )
                  );

所以现在我们返回一个 JSON 编码的数组,让我们回到 $.post 方法,看看我们现在能做什么。

//I prefer to write things out with $.ajax
$.ajax({
  url: 'booking-dialog.php',
  data: {'rowdata' : brData },
  dataType: 'json', //this is what we expect our returned data as
  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.date+'</p>');
    //the query
    $('.cp-booking-info').append('<p class="pno-margin">Query: '+data.query+'</p>');
    //the journey
    $('.cp-booking-info').append('<p class="pno-margin">Journey: '+data.journey+'</p>');
    //thepassenger tel
    $('.cp-booking-info').append('<p class="pno-margin">Passenger Tel: '+data.pass_tel+'</p>');
    //the email
    $('.cp-booking-info').append('<p class="pno-margin">Email: '+data.email+'</p>');

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

});

这是我想象的系统如何工作的最快模型。

于 2012-08-17T14:51:21.377 回答