Answer the question
In order to leave comments, you need to log in
How to implement ajax in jQuery UI?
In JQuery UI there is a so-called selectmenu, the point is to throw in the list items I need (tobish option) which in turn come json from the database, and when selecting a certain list item, make the necessary data loading from the same json ajax means, respectively . With the help of the script, I received some json (I threw off the preview, because there will be characters due to the encoding) :
{id: "1", city: "Санкт-Петербург", name: "Вася"}
{id: "2", city: "Москва", name: "Коля"}
{id: "3", city: "Тверь", name: "Петя"}
{id: "4", city: "Самара", name: "Света"}
{id: "5", city: "Великий Новгород", name: "Костя"}
{id: "6", city: "Краснодар", name: "Ира"}
{id: "7", city: "Ярославль", name: "Настя"}
<select id="selectmenu">
<option value="" selected="selected"></option>
</select>
$(document).ready(function(){
$( "#selectmenu" ).selectmenu({
change: function() {
//текущий пункт списка
alert($("#selectmenu :selected").html());
}
});
$.getJSON('mysql_json.php', function(data) {
for(var i=0;i<data.length;i++){
$('#selectmenu').append("<option>"+data[i].city +"</option>");
}
});
});
$("#my_select :selected").html();
$( "#selectmenu" ).selectmenu({
change: function() {
//текущий пункт списка
alert($("#selectmenu :selected").html());
},
open:function(){
наш ajax запрос...
});
Answer the question
In order to leave comments, you need to log in
The question is not entirely clear, although if you answer "Actually, the same ajax data loading should occur on the change event," take and substitute your ajax request into the function:
$(document).ready(function(){
$( "#selectmenu" ).selectmenu({
change: function() {
$.getJSON('mysql_json.php', function(data) {
for(var i=0;i<data.length;i++){
$('#selectmenu').append("<option>"+data[i].city +"</option>");
}
});
//текущий пункт списка
alert($("#selectmenu :selected").html());
}
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question