javascript - XMLHttpRequest is not working in QML Blackberry 10 -
in given code have used 1 label , 1 button . want when click on button request must sent json given link , print on label . code printing "ok" inside label upon success
the issue facing not getting if statement. on button clicked nothing happens. know there network manager in qt can use in situation want parse inside qml
// default empty project template import bb.cascades 1.0 // creates 1 page label page { container { layout: stacklayout {} label { id: msglabel text: qstr("hello world") textstyle.base: systemdefaults.textstyles.bigtext verticalalignment: verticalalignment.center horizontalalignment: horizontalalignment.center } button { id: requestxml objectname: "requestxml" onclicked: { var doc = new xmlhttprequest(); doc.onreadystatechange = function() { if (doc.readystate == 4) { msglabel.text="ok" // pass “doc.responsetext” c++ parsing } } doc.open("get", "http://www.example.com/sample.json", true); doc.send(); } } } }
in .pro file have declared
config += qt warn_on cascades10 qt += network config += debug config += console libs += -lbbdata qt +=script qt +=scripttools
where wrong ? or have declare thing else
i don't have access twitter api, can't test you. work other json files. example need libs += -lbbdata in .pro file. also, read datasource , jsondataaccess. if download json through c++.
import bb.cascades 1.0 import bb.data 1.0 page { container { layout: stacklayout { } label { id: msglabel text: qstr("hello world") textstyle.base: systemdefaults.textstyles.bigtext verticalalignment: verticalalignment.center horizontalalignment: horizontalalignment.center } button { id: requestxml onclicked: { datasource.load(); } } attachedobjects: [ datasource { id: datasource source: "https://api.twitter.com/1.1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=ladygaga" type: datasourcetype.json ondataloaded: { console.log("loaded"); console.log(json.stringify(data)); //just testing console.log(data); } onerror: { console.log(errortype); console.log(errormessage); } } ] }
also twitter api using no longer available check rest api v1.1 resources or following error:
{"errors": [{"message": "the twitter rest api v1 no longer active. please migrate api v1.1. https://dev.twitter.com/docs/api/1.1/overview.", "code": 68}]}
Comments
Post a Comment