我正在使用jquery和ajax在用户从下拉框中选择值时运行MySQL查询。我想将第一个和第二个下拉框中的值作为帖子传递到下一页,查询可以检查该值是否存在。
我很容易就能像这样传递一个值:
<script type="text/javascript">
$(function() {
//alert('Document is ready');
$('#block').change(function() {
var sel_stud2 = $('#username_select').val();
//alert('You picked: ' + sel_stud);
$.ajax({
type: "POST",
url: "include/block_user.php",
data: 'theOption2=' + sel_stud2,
success: function(whatigot) {
//alert('Server-side response: ' + whatigot);
$('#LaDIV2').html(whatigot);
$('#theButton').click(function() {
alert('You clicked the button');
});
} //END success fn
}); //END $.ajax
}); //END dropdown change event
}); //END document.ready
</script>
然而,当我尝试传递我的选择下拉框值时,我得到两者的索引未定义错误。这是我尝试过的。请有人告诉我我哪里出错了,谢谢
<script type="text/javascript">
$(function() {
//alert('Document is ready');
$('#block').change(function() {
var sel_stud2 = $('#username_select').val();
var sel_stud3 = $('#block').val();
//alert('You picked: ' + sel_stud);
$.ajax({
type: "POST",
url: "include/block_user.php",
data: "{'theOption2=': + sel_stud2,'theOption3=': + sel_stud3}",
success: function(whatigot) {
//alert('Server-side response: ' + whatigot);
$('#LaDIV2').html(whatigot);
$('#theButton').click(function() {
alert('You clicked the button');
});
} //END success fn
}); //END $.ajax
}); //END dropdown change event
}); //END document.ready
</script>
答案 0 :(得分:0)
@A. Wolff
是正确的。您正在引用您的对象数据(并且您的注释表明您仍然留下外部双引号):
请改为尝试:
data: {theOption2: sel_stud2,
theOption3: sel_stud3},