dongwei4444 2014-07-17 08:52
浏览 54

是否可以在ajax调用中传递变量? [关闭]

Is it possible to pass variable in ajax call?

$(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);
                    }
                });
           });

In ajax.php, I have that fuction.I want to call result function in the ajax.php I am not getting the respose.

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'];
        }
    }
} 
  • 写回答

3条回答 默认 最新

  • duanlumei5941 2014-07-17 08:54
    关注
    $(document).on('click','#Quote_create_value',function(){ 
                $template = $(this).val();
                var functionVal = result($template)
                    $.ajax({
                        type : 'GET',
                        url : '../../../protected/config/ajax.php',
                        data:"function=result("+functionVal+")",
                        success : function(response){
                            $("#Quote_template_value").html(response);
                        }
                    });
               });
    
    评论

报告相同问题?