在www / js / init-apps.js中,我建立了与服务器的通信以及填充select所需的检索数据。在页面#mainpage我有一个选择我希望选项是检索到的数据。如何从init-apps.js填充#mainpage上的选项列表,还是需要在#mainpage上放一个按钮并从那里填写?到目前为止,我没有想出一种方法来从init-app.js这样做,这是我希望填充选择的方式。这样,当应用程序显示选择将被填充,所有用户必须做的是进行选择,输入用户名和密码并登录。
答案 0 :(得分:0)
// var leagues = "";
var xhr = new XMLHttpRequest();
xhr.onload = function(){
if(xhr.status == 200) {
leagues = xhr.responseText;
// app.consoleLog(fName,leagues) ;
var slen2 = leagues.indexOf('``'); // inserted in my php program
if (slen2 > 0) {
while (leagues.length > 0) {
var slen = leagues.indexOf('``');
var leag = leagues.substring(0,slen);
var slen3 = leagues.indexOf('^^'); // inserted in my php program
var _id = leagues.substring(slen+2,slen3);
$('#leagueid').append($("<option value= "+_id+">"+leag+"</option>"));
leagues = leagues.substr(slen3+2, leagues.length );
}
}
}
else if(xhr.status == 404)
{
navigator.notification.alert("Web Service Doesn't Exist", "Error");
}
else
{
navigator.notification.alert("Unknown error occured while connecting to server", "Error");
}
};
xhr.open("GET", "http://www.?????.com/dartleague/?????.php?my??=0");
xhr.send();
// #leagueid is ID of the select control