何らかの理由でPOST
の変数がform
から常に空です。ここに私のコードです... 私は、ドロップダウン(選択)から新しい項目を選択すると表示される情報を返すブートストラップの選択肢を持っています。Ajaxが値を返した後のPHP投稿
コード:
$(function() {
$("#shiftsDD").change(function(){
var selectedItemId = $('#shiftsDD option:selected').val();
$.post('/step/services/shiftInfo.php', { shiftID : selectedItemId }, function(res){
$("#shiftCard").show();
var jsonRes = $.parseJSON(res);
$("#address").html(jsonRes[0]);
$("#duties").html(jsonRes[1]);
$("#employer").html(jsonRes[4]);
$("#payRate").html(jsonRes[5]);
$("#theShiftID").html(jsonRes[6]);
console.log(res);
});
});
});
jsonRes配列から、これらの値のすべてがここに割り当てられます。
<form role="form" name="cardForm" method="POST">
<div class="card" id="shiftCard">
Employer:
<h3 id="employer">Test Employer</h3><br>
Address:
<h3 id="address">Test Address</h3><br>
Duties include:
<h3 id="duties">Test duties</h3><br>
Pay rate:
<h3 id="payRate">Test PayRate</h3><br>
<h5 id="theShiftID" name="myShiftID"></h5>
<br>
<button type="submit" class="btn btn-lg btn-green-solid" name="shiftsBtn">Accept work</button>
</div>
</form>
私は物事の多くを試みたが、私はアヤックスではなくプロに新しいですなぜPHPで私は知りません。
if (isset($_POST['shiftsBtn'])) {
$theId = $_POST['myShiftID'];
...
myShiftID
は常に空です
は、コードを選択ShiftsDD:
http://php.net/manual/en /function.error-reporting.phpとあなたのコンソールを見てください。 –
が追加され、コンソールにエラーは表示されません。私は受け取って、私はAJAXからの値を表示するが、私は送信ボタンを押すと、ポスト変数が空(未定義のインデックス)であり、上記のコードがうまく見えることがわかります – iBobb
'
' - わたしの知る限り、H要素は(POST可能な)入力として扱われません。あなたはDOMでこれを行うことができますが、今やっているやり方ではできません。 * "未定義のインデックス" *私はあなたがエラー報告を使用するように頼んだ理由を知っています。 –