我想你的代码有一些硬编码值,并将其完美的罚款工作: -
HTML + jQuery的(与html扩展单页): -
--Select--
Value1
Value2
function getPrice(val) {
$.ajax({
type: 'post',
url: 'get_sales_price.php',
data: {
get_option: val
},
dataType: 'json',
success: function(response) {
console.log(response)
$('#freeitem').html(response.fritm);
}
});
}
PHP(用硬编码值): -
$option = $_POST['get_option'];
$data = array();
$data['fritm'] = ''; // you need to define it as empty string first
for($i = 0;$i<10;$i++) // hard-code started
{
$data['fritm'] .= ''.$i.''; // append each option to the string one-by-one and check `.=` also
}
echo json_encode($data);
输出: -
注: - 问题可能是存在的,因为无论你错过了内循环或其他错误拼接的jQuery库在你的PHP文件。