jquery加载传递参数

时间:2017-04-26 01:10:32

标签: php jquery

您好想问一下使用jquery传递参数的正确方法是什么我的参数来自html输入,下面是我的代码。

function ajax_post(){


            var param = document.getElementById('def').value;


            $('#chatlogs').load('main.php?id='+param);



    }

我可以加载main.php,但无法回显param,这是我的main.php代码。

<?php echo $_GET['id'];?>  

添加更多细节..我从HTML选择输入中获取参数然后在获取值之后,将main.php加载到id为#chatlogs的div中。

<select name="topic" id="def" class="form-control" style="width:450px;" onChange='ajax_post()'>
                        <option value="" selected>---</option>
                        <option value="Solder Short">Solder Short</option>
                        <option value="Insufficient Solder">Insufficient Solder</option>
                        <option value="Misaligned Component">Misaligned Component</option>
                        <option value="Missing Component">Missing Component</option>
                        <option value="Inverted Component">Inverted Component</option>
                        <option value="Pad Contamination">Pad Contamination</option>


                    </select>  


<div id="chatlogs">
Please select a defect category...
</div>

enter image description here

2 个答案:

答案 0 :(得分:0)

试试这个:

function ajax_post(){

var param = document.getElementById('def').value;

$('#chatlogs').load('main.php?id='+param);

}

答案 1 :(得分:0)

试试这个:

<select name="topic" id="def" class="form-control" style="width:450px;">
                        <option value="" selected>---</option>
                        <option value="Solder Short">Solder Short</option>
                        <option value="Insufficient Solder">Insufficient Solder</option>
                        <option value="Misaligned Component">Misaligned Component</option>
                        <option value="Missing Component">Missing Component</option>
                        <option value="Inverted Component">Inverted Component</option>
                        <option value="Pad Contamination">Pad Contamination</option>


                    </select>  


<div id="chatlogs">
Please select a defect category...
</div>

<script>
$(document).ready(function(){
    $('#def').on('change', function() {
        var param = document.getElementById('def').value;
        //alert(param);

        $('#chatlogs').load('main.php?id=', param);
    })
});
</script>