我想在用户点击选择控件或选择控件从键盘获得焦点时调用 ajax 函数。
HTML代码如下:
<select id="scanner" name="scanner" class="form-control"></select>
我写的 jQuery-AJAX 函数如下,但是 aler("Hello") 没有被打印出来。为什么会这样?
$("#scanner").bind("change",function() { alert("Hello");
var mod_url = $('#mod_url').val();
$.ajax({
url : mod_url,
cache: false,
dataType: "json",
type: "GET",
async: false,
data: {
'request_type':'ajax',
'op':'get_all_stores'
},
success: function(result, success) { alert(result);
$('#scanner').html(result);
},
error: function() {
alert("Error is occured");
}
});
});
最佳答案
在你的code
我还没有看到任何options
对于 html select
盒子
并且,您已经注册了一个change
事件 select
只有在选择 options
时才会出现的框在select
盒子
添加几个options
在选择框中并尝试选择将触发 ajax 调用的选项
关于javascript - 为什么没有调用 AJAX 函数并且在调用该函数时没有打印警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27498888/