誰能幫助我?
我有一個將參數(從數組中取出)帶入PHP $ _POST的問題。 $ ajax發送的參數已經填滿了。當我嘗試將整個數組抓到PHP腳本中時,沒有可用的$ _POST或$ _GET。我錯了什麼。我也試過它也是單參數,也失敗了。我嘗試了所有可能的方式來抓取參數($ _GET以及$ _POST)。我錯了什麼?
例如輸入已被定義如下,做工精良
- 例如輸入已被定義如下,做工精良
<div class="site input"> <i class="icon-pend icon calendar"></i>
<input name="fromdate" type="text" data-datepicker="true" value="<?php if($_POST['fromdate'] <> ""){ echo $_POST['fromdate'];} else{echo $_GET['fromdate'];} ?>" placeholder="<?php echo Lang::$word->FROM;?>" id="fromdate" data-bind="<?php if($_POST['fromdate'] <> ""){ echo $_POST['fromdate'];} else{echo $_GET['fromdate'];} ?>"></div>
- 帖子看起來像下面這樣
function createVerzuimServiceReport1()
{
var pg='<?php echo $_GET['pg'] ?>';
var ipp='<?php echo $_GET['ipp'] ?>';
var fromdate_submit=$('input[name="fromdate_submit"]').val();
if(fromdate_submit=='') {
fromdate_submit='<?php echo $_GET['fromdate_submit'] ?>'; }
var enddate_submit=$('input[name="enddate_submit"]').val();
if(enddate_submit=='') {
enddate_submit='<?php echo $_GET['enddate_submit'] ?>'; }
var date = new Date(Date.parse($('#fromdate').val())),
d = ("0" + date.getDate()).slice(-2),
m = ("0" + (date.getMonth() + 1)).slice(-2),
y = date.getFullYear(),
fDate = y + '-' + m + '-' + d;
var date = new Date(Date.parse($('#enddate').val())),
d = ("0" + date.getDate()).slice(-2),
m = ("0" + (date.getMonth() + 1)).slice(-2),
y = date.getFullYear(),
lDate = y + '-' + m + '-' + d;
var postData = { };
postData.action = "postData";
postData.createVerzuimServiceReport1 = "createVerzuimServiceReport1";
postData.fromdate_submit = fDate;
postData.enddate_submit = lDate;
postData.studentsearchfield = $('#filter').val();
$.ajax({
type: "post",
url: "../plugins/registereddayvr/controller_verzuim_tot.php",
data: postData,
dataType: "json",
success: function(data) {
alert(postData.action + ' ' + postData.createVerzuimServiceReport1 + ' ' + postData.fromdate_submit + ' ' + postData.enddate_submit + ' ' + postData.studentsearchfield);
alert(postData.action + ' ' + postData.createVerzuimServiceReport1 + ' ' + postData.fromdate_submit + ' ' + postData.enddate_submit + ' ' + postData.studentsearchfield);
window.open("../plugins/registereddayvr/controller_verzuim_tot.php", "MsgWindow", "width=800, height=900");
if(data.fout)
alert('FOUT BERICHT: ' + data.bericht);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
};
- PHP的看起來像這樣
if(isset($_POST['action']) && $_POST['action'] == "postData") { //if(isset($_GET['action']) && $_GET['action']== "postData")
$vals = array(
'action' => $action,
'createVerzuimServiceReport1' => $createVerzuimServiceReport1,
'fromdate_submit' => $fromdate_submit,
'enddate_submit' => $enddate_submit,
'studentsearchfield' => $studentsearchfield
);
// JSON encode er zijn params gevonden verstuur naar $.ajax success.
echo 'resultaat is: '.json_encode($vals);
exit; // zeker weten dat er niets anders is
}
else { // zo is er toegang tot de fout bericht in jQuery
echo json_encode(array('fout' => TRUE, 'bericht' => 'Een probleem is ontstaan! Fout is: Er zijn geen parameters ontvangen in controller_verzuim_tot.php...', 'get' => $_GET, 'post' => $_POST,));
exit;
}
我已經檢查了所有在stackoverflow上發佈的答案,並閱讀了很多關於此主題的消息,並且我已經跟蹤了一些答案,但發件人($ _POST)不存在。我錯了什麼?感謝您的回答。
我會建議你開始一個簡單的情況,而你還在學習。檢查這個問題的答案,例如http://stackoverflow.com/a/5004276/204610 – Michael
邁克爾,我試過哪些也不起作用。 –