-3
這是我嘗試的代碼,但是當我選擇一個項目時,它顯示一些數組輸出我只想要我選擇的特定值。像白房子顯示具體值
<select id="item">
<option value="">Please select</option>
<option value="white-house">The White House</option>
</select>
<div id="results"></div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
function makeAjaxRequest(opts){
$.ajax({
type: "POST",
data: { opts: opts },
url: "tryonly.php",
success: function(res) {
$("#results").html("<p> " + res + "</p>");
}
});
}
$("#item").on("change", function(){
var selected = $(this).val();
makeAjaxRequest(selected);
});
</script>
在PHP代碼
<?php
echo '<pre>';
print_r($_POST);
echo '</pre>';
?>
輸出的時候我選擇項目
Array
(
[opts] => white-house
)
那就是'的print_r()'做...... – jeroen
如何輸出具體的值? –
'echo $ _POST ['opts']'' – Peon