0

AJAX を使用して jQuery 変数を PHP に渡そうとしていますが、渡されていないようです。テスト目的で、次のものがあります。

Jクエリ:

            var runin_pickup = 1200;

            // Send to our checkRuninTariff function
            checkRuninTariff(runin_pickup);

`

function checkRuninTariff(runin_pickup) {

$.ajax({

         // Request sent from control panel, so send to cp.request.php (which is the handler)
        url: 'scripts/php/bootstrp/all.request.php',
        type: 'POST',

        // Build data array - look at the '$_REQUEST' parameters in the 'insert' function
        data: 'fnme=runIn&field_runin_p='+runin_pickup,
        dataType: 'text',
        timeout: 20000,
        error: function(){
                alert("There was a problem...")
        },
        success: function(){
                alert(runin_pickup+' passed successfully')
        }
    });

}

これは all.request.php に渡されます:

<?php

include('../../../deployment.php');
require_once('controllers/xml.controller.php');
require_once('controllers/tariff.fare.controller.php');
require_once('controllers/datagrid.controller.php');
require_once('controllers/get.bookings.php');


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

case 'runIn':
header('Content-type: text/html');
echo TariffFareController::getFare($_REQUEST['field_runin_p']);
break;

case 'g_fare':

header('Content-type: text/html');

echo TariffFareController::fareRequestHandler($_REQUEST['v_sys'],$_REQUEST['j_dis'],$_REQUEST['pc_arr'],
    $_REQUEST['leg_arr'],$_REQUEST['return_j'],$_REQUEST['j_date'],$_REQUEST['j_time'],
    $_REQUEST['r_date'],$_REQUEST['r_time'],$_REQUEST['wait_return_j']);

break;
}

そして最後に、料金表.fare.controller.php に移動します:

public static function getFare($int_terminate,$fieldPickup) {

        if($fieldPickup > 1100) {

            $fare = 222.00;
        }
        else {
        $fare = 111.00;
        }

}

firebugコンソールで私はそれを見ることができますfield_runin_p = 1200

ただし、var_dump($fieldPickup); を実行すると、これは NULL であるべき場合に NULL1200です。これが機能しない理由はありますか?

どんな助けでも大歓迎です!

4

2 に答える 2

1

関数には 2 つの引数が必要です。

getFare($int_terminate, $fieldPickup)

ただし、コードは1つだけを渡します(そして、期待している変数と一致しません):

echo TariffFareController::getFare($_REQUEST['field_runin_p']);

于 2013-03-13T16:42:08.443 に答える
0

PHP から html を送信しようとしてheader('Content-type: text/html');いますが、javascript にプレーンテキストを期待するように指示しています。dataType: 'text',

header('Content-type: text/plain');代わりに使用してください。

他の投稿者は、スクリプトの他の問題を指摘しています。

また$_REQUEST、データが GET または POST パラメーターから取得されている可能性があり、どちらを使用するかわからないため、使用しないことをお勧めします。

于 2013-03-13T16:47:55.740 に答える