这是我试过的代码:
function show(date,meal){
var parameters = 'q='+date '&m='+meal;
var argUrl = 'meal1.php';
$.ajax({
url: argUrl,
type: 'POST',
data: parameters,
success: function (str) {
$('#txtHint').html(str);
//alert(parameters);
}
});
}
我的表单:
<form method="post">
<input type="text" id="datewise" name="datewise" value="" class="form- control input-datepicker-close" placeholder="dd/mm/yy" >
<select id="mealplan" name="mealplan" class="form-control" onchange="shownoofroom(this.value);">
<option value=""> Select </option>
<?php $sql = "select *from mean_plan";
$retval = mysql_query( $sql, $conn );
if(! $retval ){
die('Could not get data: ' . mysql_error());
echo 'Could not get data: ' . mysql_error();
}
while($row = mysql_fetch_array($retval,MYSQL_ASSOC)){ //roll id if
//$roll_id= $row['roleid'];
?>
<option value="<?php echo $row['meanplan']?>"><?php echo $row['meanplan']?></option>
<?php
}
?>
</select>
<input type="buttton" class="btn btn-info btn-primary " onclick="show('<?php $_POST['datewise'];?>','<?php $_POST['mealplan'];?>')name="submit">
</form>
<div id="txtHint">
这是将参数传递给函数的正确方法吗? 或者我如何在onclick事件中传递表单值并将其存储在函数变量中。
答案 0 :(得分:1)
这没关系
function show(date,meal){
var argUrl = 'meal1.php';
$.ajax({
url: argUrl,
type: 'POST',
data: {
date:date,
meal:meal
},
success: function (str) {
$('#txtHint').html(str);
//alert(parameters);
}
});
}