Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
传递Jquery变量以在php脚本中使用_Php_Jquery - Fatal编程技术网

传递Jquery变量以在php脚本中使用

传递Jquery变量以在php脚本中使用,php,jquery,Php,Jquery,我有一个预订表格,如下所示: 在这个预订网格上,我有一个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: &nb

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

在这个预订网格上,我有一个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>
其中brData是我希望在PHP脚本中使用的“Booking Reference”值。此时,此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

    }
});
最后是要使用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;

    }


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

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


如果有人能帮我做这件事,我将非常感激,因为我已经努力让它工作了很长一段时间了:

你为什么这样发送它

 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,请尝试仅使用$\u REQUEST['row\u data']或使用上面的示例将变量$\u 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

    }
});
-

看看你的代码:

第二行覆盖了第一行,因此可以删除rowData=newarray

现在,您确定存在$\u请求['fName']吗?switch语句没有任何默认值,看起来getGridRow永远不会执行

另外,$rowdata=$\u请求['rowdata']没有意义,您可以删除它


我希望它能帮助您。

对不起,我已经对代码进行了编辑,基本上我只需要传递一个值;rowdata:brData,我已尝试将$\u REQUEST['row\u data']添加到我的查询中,但不起作用现在您不发送$\u REQUEST['fname'],因此无法传递开关盒结构。也编辑了我的示例。要调试它,请在切换结构之前回显php脚本中的行数据。您应该看到正确的brData值-并删除$rowdata=$\u请求['rowdata'];从getGridRow函数中,您希望将其作为参数传递。在函数中覆盖它可能会在测试脚本时引起问题。将值作为参数传递应该足够感谢您的帮助,我已将代码更改为此,并添加了“echo$rowdata;”去GetBooking班。在firebug控制台中,我可以看到它显示了正确的值,因为它返回BR1274,这是我单击的行。但是,这仍然不起作用,我不确定这是否是因为在进行PHP查询之前正在加载对话框??如果我给您提供了查看此对话框的链接,会有帮助吗?通过更改此链接,brData值现在为“未定义”。如果是,我想您可以删除第一行,并将第二行更改为自己的。第一行在这里没有任何意义。还有一个问题-您遇到的问题是脚本没有发出任何警报?如果是这样的话,如果您希望从PHP的GetGridRow返回,那么您必须使用rowData[0]['bookref'],但这只是一个细节。只有rowData=新数组;是不必要的,可以在原稿中删除code@Asto,你说得对,我在评论中写道,第一行可以删除。我在等着改变我的答案,我不想只做我的答案解决方案是的,我已经删除了,它不必存在
 data: {

    fname: 'getDGRow',
    rowdata: brData,

    id: null,
    condition: null
},
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;

    }


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