php while
中有这样的下拉菜单
<tr id='row<?php echo $row_number;?>'>
...
<td>
<select name="currency[]" id="currency<?php echo $row_number;?>" >
<option value=""></option>
<option value="AUD">AUD</option>
<option value="EUR">EUR</option>
<option value="USD">USD</option>
</select>
</td>
</tr>
在html
输出中获得多个这样的菜单(因为php while
)
ajax
尝试将值传递到外部php文件。
$(document).ready(function () {
function sendCurrencies() {
function autosave(suffix) {
if (($("#currency" + suffix).val()).length > 0) {
alert($("#currency" + suffix).val());
$.post(
"__foreign_currency_rate.php",
$("#row" + suffix + " :input").serialize(),
function (data) { $('#load' + suffix).html(data); }
);
}//if ( ($("#currency" + suffix).val()).length > 0 ) {
}//function autosave(suffix) {
$('[id^="currency"]').each(function (index, currency) {
var suffix = currency.id.substring(8);
autosave(suffix);
});
}//function sendCurrencies() {
setInterval(sendCurrencies, 6000);
});//$(document).ready(function() {
假设问题/问题可能在代码$.post("__foreign_currency_rate.php", $("#row" + suffix + " :input").serialize(),
的这一部分
在外部php
文件中,首先要检查我得到的
echo '<pre>';
print_r($_POST['currency']);
echo '</pre>';
例如,php while
3个循环,因此获得3个下拉菜单。第一个选择澳元,第二个选择欧元,第三个选择美元。
使用print_r($_POST['currency']);
,期望看到所有值。
但只看到两个值
Array
(
[0] => EUR
)
Array
(
[0] => AUD
)
但使用alert($("#currency" + suffix).val());
弹出菜单显示所有值。
为什么用php
不能看到所有值的问题在哪里?
由于无法理解的原因,$("#row" + suffix + " :input").serialize()
只传递了2个值。。。
尝试在mysql
中记录下拉菜单值。记录的所有值。但使用print_r
并不能打印所有值。疯狂的事情。。。。
试试这个
$.post("__foreign_currency_rate.php", $("#currency" + suffix + " :input").serialize(), function(data) {
$('#load' + suffix).html(data);
});