0

我有一个预订网格,如下所示:

在此处输入图像描述

在这个预订网格上,我有一个 dblClick 事件,它打开了一个 Jquery 对话框:

<div id="cp-bookings-dialog">

    <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">Return Date: &nbsp;<strong><? echo BookingDocket::get_bookdate(); ?></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>

 </div>

jQuery代码:

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

        getGridRow(brData);

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

其中 brData 是我想在我的 PHP 脚本中使用的“预订参考”值。目前这个 dblClick 事件被发送到以下 Ajax 请求:

function getGridRow(brData) {

   $.ajax({

    url: 'scripts/php/bootstrp/all.request.php',
    type: 'POST',

    data: {

        rowdata: brData,

        id: null,
        condition: null
    },
    dataType: 'text/xml',
    timeout: 20000,
    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(response){

        // Refresh page

        //response = brData;
        //alert(response);  <--- This alerts the correct Booking Reference

    }
});

哪个被发送到 all.request.php

// Switch to determine method to call
switch ($_REQUEST['fnme']) {

case 'getDGRow':
header('Content-type: text/xml');
GetBookings::getGridRow($_REQUEST['rowdata']);
break;

最后到我想使用这个 Jquery 值的 PHP 脚本:

class GetBookings {

public static function getGridRow($rowdata) {

    $rowdata = $_REQUEST['rowdata'];

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

    try {

        $query = "SELECT * FROM tblbookings WHERE bookref = '$rowdata'";

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

            $stmt->execute();

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

            {variables are all here}

        $stmt->closeCursor();

    }

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

    $dbh = null;

    }


    }

我不知道为什么,但这似乎不起作用。另外,请注意,当您 dblClick 预订时,这会打开一个 jQuery 对话框,其中显示有关预订的所有详细信息,并且应该返回所有结果$query = "SELECT * FROM tblbookings WHERE bookref = '$rowdata'";

我需要做的就是正确地传递这些数据,这就像我$rowdata用预订参考值替换一样,它应该可以正常工作。

如果有人可以帮助我解决这个问题,我将非常感激,因为我已经尝试了很长一段时间了:(

4

2 回答 2

1

你为什么要发送它

 data: {

    rowdata: 'fnme=getDGRow&row_data='+brData,

    id: null,
    condition: null
},

不喜欢

 data: {

    fname: 'getDGRow',
    rowdata: brData,

    id: null,
    condition: null
},

在 php 文件中,您可以使用$_POST['fname']$_POST['rowdata']获取单个值。

目前,$_REQUEST['rowdata']是你的整个字符串'fnme=getDGRow&row_data='+brData

如果您想在 mysql 查询中使用 brData,请尝试使用$_REQUEST['row_data']或使用我上面的示例来正确设置变量$_REQUEST['rowdata']


你的整个代码应该可以工作

function getGridRow(brData) {

   $.ajax({

    url: 'scripts/php/bootstrp/all.request.php',
    type: 'POST',

    data: {

        fnme: 'getDGRow',
        rowdata: brData,

        id: null,
        condition: null
    },
    dataType: 'text/xml',
    timeout: 20000,
    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(response){

        // Refresh page

        //response = brData;
        alert(response); // <--- This alerts the correct Booking Reference

    }
});

-

// Switch to determine method to call
switch ($_REQUEST['fnme']) {

case 'getDGRow':
header('Content-type: text/xml');
GetBookings::getGridRow($_REQUEST['rowdata']);
break;

-

class GetBookings {

public function getGridRow($rowdata) {

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

    try {

        $query = "SELECT * FROM tblbookings WHERE bookref = '$rowdata'";

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

            $stmt->execute();

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

            {variables are all here}

        $stmt->closeCursor();

    }

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

    $dbh = null;

    }


    }
于 2012-07-10T08:51:12.647 回答
0

Look at your code:

var rowData = new Array();
    rowData = $("#bookings").getRowData(rowid);
    var brData = rowData['bookref'];

The second line overwrited the first line, so you can delete rowData = new Array().

Now, are you sure that $_REQUEST['fnme'] exists? Your switch statement doesn't have any default value, and it looks like getGridRow() will never be executed.

Additionaly, $rowdata = $_REQUEST['rowdata'] is meaningless, you can remove it.

I hope it helps you.

于 2012-07-10T09:34:38.627 回答