Javascript 使用WinJS获取JSON Twitter搜索数据

Javascript 使用WinJS获取JSON Twitter搜索数据,javascript,json,windows,xmlhttprequest,winjs,Javascript,Json,Windows,Xmlhttprequest,Winjs,正在尝试验证以在Windows 8应用程序中接收来自Twitter的搜索数据源。这是直接从一本书上写的,当时Twitter不需要身份验证,所以它应该可以工作,尽管我添加了用户和密码,但没有任何结果(更糟糕的是,应用程序终止) JS: HTML: 谢谢-将其更改为,使应用程序现在可以更快地终止,但仍然没有结果…您是否阅读了来自该URL的响应{“错误”:[{“消息”:“错误的身份验证数据”,“代码”:215}]}在Visual Studio 2013的任何地方都看不到错误(尽管我仍在学习应用程序方

正在尝试验证以在Windows 8应用程序中接收来自Twitter的搜索数据源。这是直接从一本书上写的,当时Twitter不需要身份验证,所以它应该可以工作,尽管我添加了用户和密码,但没有任何结果(更糟糕的是,应用程序终止)

JS:

HTML:



谢谢-将其更改为,使应用程序现在可以更快地终止,但仍然没有结果…您是否阅读了来自该URL的响应<代码>{“错误”:[{“消息”:“错误的身份验证数据”,“代码”:215}]}在Visual Studio 2013的任何地方都看不到错误(尽管我仍在学习应用程序方面的知识)。当然不是在JS控制台或页面上。它在base.js中的terminateAppHandler中终止。如果XHR请求中出现错误,请在
then()
调用中添加第二个函数,然后您就可以捕获错误了@jakerella提到过,您缺少error handler函数。看看这篇文章:
        args.setPromise(WinJS.UI.processAll().then(function () {

            WinJS.xhr({
                url: "http://search.twitter.com/search.json?q=windows8",
                //type: "GET",
                user: "myusername",
                password: "mypassword"
            }).then(
            function (result) {
                var jsonData = JSON.parse(result.responseText);
                //create a binding list object from the json
                var bindingList = new WinJS.Binding.List(jsonData.results);
                //get the list view element from the DOM
                var listView = document.getElementById("sampleListView").winControl;
                //bind the data sources
                listView.itemDataSource = bindingList.dataSource
            });
        }));
<div id="sampleListView" data-win-control="WinJS.UI.ListView"></div>