
http://query.yahooAPIs.com/v1/public/yql?q=select%20item%20from%20weather.forecast%20where%20location%3D%223015%22&format=Json
我尝试使用此功能进行一些修改
function getdocument(url) { var templateXHR = new XMLhttpRequest(); templateXHR.responseType = "Json"; templateXHR.open("GET",url,true); templateXHR.send(); return templateXHR;} 但没有成功.任何提示或帮助?
如果我需要使用NodeJs,我该怎么办?
解决方法 这是我工作的一个.它在许多方面都不是理想的,但是向您展示了一些入门的东西.function JsonRequest(options) { var url = options.url; var method = options.method || 'GET'; var headers = options.headers || {} ; var body = options.body || ''; var callback = options.callback || function(err,data) { console.error("options.callback was missing for this request"); }; if (!url) { throw 'loadURL requires a url argument'; } var xhr = new XMLhttpRequest(); xhr.responseType = 'Json'; xhr.onreadystatechange = function() { try { if (xhr.readyState === 4) { if (xhr.status === 200) { callback(null,JsON.parse(xhr.responseText)); } else { callback(new Error("Error [" + xhr.status + "] making http request: " + url)); } } } catch (err) { console.error('Aborting request ' + url + '. Error: ' + err); xhr.abort(); callback(new Error("Error making request to: " + url + " error: " + err)); } }; xhr.open(method,true); Object.keys(headers).forEach(function(key) { xhr.setRequestheader(key,headers[key]); }); xhr.send(); return xhr;} 您可以使用以下示例调用它:
JsonRequest({ url: 'https://API.github.com/users/staxmanade/repos',callback: function(err,data) { console.log(JsON.stringify(data[0],null,' ')); }}); 希望这可以帮助.
总结以上是内存溢出为你收集整理的javascript – 通过TVJS-tvOS消费API JSon调用全部内容,希望文章能够帮你解决javascript – 通过TVJS-tvOS消费API JSon调用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)