Я пытаюсь передать переменную jQuery в PHP с помощью AJAX, но она, похоже, не проходит. Для целей тестирования у меня есть следующие:jQuery - Передача переменной в PHP
Jquery:
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, если оно должно быть 1200
. Любые идеи, почему это не работает?
Любая помощь была бы высоко оценена!