是否有可能在ajax调用中传递变量?是否可以在ajax调用中传递变量?
$(document).on('click','#Quote_create_value',function(){
$template = $(this).val();
$.ajax({
type : 'GET',
url : '../../../protected/config/ajax.php',
data:"function=result($template)",
success : function(response){
$("#Quote_template_value").html(response);
}
});
});
在ajax.php,我有fuction.I想调用结果函数在ajax.php 我没有得到生存。
if(isset($_GET['function'])) {
if($_GET['function'] == 'templateDropDown') {
$query = "select * from quote where template IS NOT NULL";
$result = mysql_query($query, $con);
while ($row = mysql_fetch_assoc($result)) {
echo '<option value="'.$row['template'].'">' . $row['template'] . '</option>';
}
mysql_free_result($result);
}
elseif($_GET['function'] == 'result($template)') {
$query = "select * from template where templateName=$template";
$result = mysql_query($query,$con);
while ($row = mysql_fetch_assoc($result)) {
echo $row['unitcost'];
}
}
}
请参阅http://stackoverflow.com/questions/18413969/pass-variable-to-function-in-jquery-ajax-success-callback –
我假设您想要$ template为var'template'? – t3chguy
现在这个问题还不是很清楚。结果是一个PHP函数吗? –