[英]jQuery AJAX POST gives undefined index
我的eventinfo.php提供以下輸出:
<br />
<b>Notice</b>: Undefined index: club in <b>/homepages/19/d361310357/htdocs/guestvibe/wp-content/themes/yasmin/guestvibe/eventinfo.php</b> on line <b>11</b><br />
[]
HTML(index.php):
<select name="club" class="dropdown" id="club">
<?php getClubs(); ?>
</select>
jQuery(index.php):
<script type="text/javascript">
$(document).ready(function() {
$.ajax({
type: "POST",
url: "http://www.guestvibe.com/wp-content/themes/yasmin/guestvibe/eventinfo.php",
data: $('#club').serialize(),
success: function(data) {
$('#rightbox_inside').html('<h2>' + $('#club').val() + '<span style="font-size: 14px"> (' + data[0].day + ')</h2><hr><p><b>Entry:</b> ' + data[0].entry + '</p><p><b>Queue jump:</b> ' + data[0].queuejump + '</p><br><p><i>Guestlist closes at ' + data[0].closing + '</i></p>');
},
dataType: "json"
});
});
$('#club').change(function(event) {
$.ajax({
type: "POST",
url: "http://www.guestvibe.com/wp-content/themes/yasmin/guestvibe/eventinfo.php",
data: $(this).serialize(),
success: function(data) {
$('#rightbox_inside').hide().html('<h2>' + $('#club').val() + '<span style="font-size: 14px"> (' + data[0].day + ')</h2><hr><p><b>Entry:</b> ' + data[0].entry + '</p><p><b>Queue jump:</b> ' + data[0].queuejump + '</p><br><p><i>Guestlist closes at ' + data[0].closing + '</i></p>').fadeIn('500');
},
dataType: "json"
});
});
</script>
我可以從jQuery運行警報,因此它是活動的。
我已經從舊版本的網站上復制了這個,但是我已經改變了文件結構(通過移動到WordPress),所以我懷疑這些變量甚至可能不會首先到達eventinfo.php ......
index.php在wp-content / themes / cambridge中,eventinfo.php在wp-content / themes / yasmin / guestvibe中,但我試圖通過完全引用URL來避免構造問題。
有任何想法嗎?
編輯
對不起,忘了eventinfo.php。 我懷疑只有第3行才有用,但我可能錯了。
include('functions.php');
connect();
$night = $_POST['club'];
$night = mysql_real_escape_string($night);
$query = "SELECT * FROM nights WHERE name = '" .$night. "'";
$result = mysql_query($query);
$items = array();
if($result && mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_array($result)) {
$items[] = array("entry"=>$row['entry'], "day"=>getLongDateString($row['day']), "queuejump"=>$row['queue jump'], "closing"=>$row['closing']);
}
}
mysql_close();
// convert into JSON format and print
echo json_encode($items);
?>
vardump [$ _ POST]給出:
array(0) {
}
在index.php文件中,您有:
<select name="club" class="dropdown" id="club">
<?php getClubs(); ?>
</select>
將此更改為(更新) :
<form name="myform" id="myform" action="submit.php" method="POST">
<select name="club" class="dropdown">
<?php getClubs(); ?>
</select>
</form>
然后將代碼更改為$('#myform').serialize()
而不是$('#club').serialize()
$ _POST ['club']為空,這就是你收到通知的原因。 它是null,因為它沒有正確提交。 必須提交表單,而不是select元素。 表單本身必須是serialize()
,而不是select元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.