为什么在调用该函数时未调用AJAX函数并且未打印警报? [英] Why the AJAX function is not getting called and alert is not getting printed upon calling the function?
问题描述
我想在用户单击选择控件或选择控件从键盘将焦点转移到自己后调用ajax函数。
I want to call the ajax function once user clicks on the select control or the select control gets focus to itself from keyboard.
HTML代码如下:
<select id="scanner" name="scanner" class="form-control"></select>
我编写的jQuery-AJAX函数如下,但aler( Hello)没有得到打印。为什么这样?
The jQuery-AJAX function I wrote is as follows but the aler("Hello") is not getting printed. why so?
$("#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");
}
});
});
推荐答案
在您的代码中
我没有看到任何选项
用于HTML 选择
框
In your code
i haven't seen any options
for html select
box
而且,您已经在 select
框上注册了更改
事件,该事件仅在选择选择
框中的选项
And, you have registered a change
event on select
box which will occur only on selecting the options
in select
box
添加一些选项
,然后尝试选择将触发ajax调用的选项
Add few options
in select box and try to select options which will fire the ajax call
请参见 此处的JS
这篇关于为什么在调用该函数时未调用AJAX函数并且未打印警报?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!