且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用JavaScript从Windows商店应用程序中的Web服务获取数据

更新时间:2023-10-19 19:36:22

您好,

您可以使用ajax调用,但建议您使用
WinJS.xhr
(你不需要jQuery真的)。

You can use ajax calls but it's recommended you use WinJS.xhr (you don't need jQuery really).

//in your Page Control html file
<select id="CbxArea" style="width: 200px">

    <option>Select Area</option>

</select>

//in your Page Control's js file, which would be the advised way to separate html from js

ready: function (element, options) {
//some code you may already have
 WinJS.xhr({url: "webservice_url" }).done(function (datas) {
var data = JSON.parse(datas.responseText);
var innerhtml='';
for (i = 0; i < data.length; i++) {
innerhtml+='<option>'+data[i].AreaName+'</option>';
}
element.querySelector('#CbxArea').innerHTML = innerhtml;
}, function(error){
//handle connection errors
});
//rest of the initialization code of the Page Control's js file
},
//rest of your page's js file