我创建了从数据库中选择数据的选择,但为选择器设置 ID =“myselect”
但是如果我选择了一个项目并且当用户点击其项目时更改为我想要调用ajax的其他项目,则此ajax将调用。
$(document).on("click", "#myselect", function (e) {
$.ajax({
url: '/teller/assignTo',
dataType: 'json',
Method: 'get',
success: function (data, status) {
var userId = data.users;
$.each(userId, function (key, value) {
$('#myselect').append($("<option></option>").attr("value", key).text(value.name));
});
},
error: function () {
throw new Error("Could not load " + data);
}
});
});
HTML
<select name="assign_user_id" id="myselect" class="form-control" ></select>
答案 0 :(得分:1)
试试这个
HTML
<select name="assign_user_id" id="myselect" class="form-control not-clicked" ></select>
JQuery的
$(document).on("click", "#myselect", function (e) {
if( $(this).hasClass( "not-clicked" ) ) {
$.ajax({
url: '/teller/assignTo',
dataType: 'json',
Method: 'get',
success: function (data, status) {
var userId = data.users;
$.each(userId, function (key, value) {
$('#myselect').append($("<option></option>").attr("value", key).text(value.name));
});
},
error: function () {
throw new Error("Could not load " + data);
}
});
$(this).removeClass("not-clicked");
}
});