2011/07/07

How to make JSONP call in GWT

Example goes here:

String url3 = "https://ajax.googleapis.com/ajax/services/search/news?v=1.0&q=barack%20obama"; JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); //jsonp.setCallbackParam("callback"); //gwt will generate a java script object of url "http://url_of_some_service?para=value%callback=_xxxx_onSuccess" //the _xxxx_onSuccess points to below onSucess function. jsonp.requestObject(url3, new AsyncCallback<javascriptobject>() { public void onFailure(Throwable throwable) { GWT.log("got the JavaScriptObject"); Window.alert("jsonp failed"); } public void onSuccess(JavaScriptObject feed) { JSONObject obj = new JSONObject(feed); JSONValue val = obj.get("responseStatus"); if(val != null) { JSONNumber num = val.isNumber(); Window.alert("got the responseStatus " + num.doubleValue()); } else { Window.alert("not getting the responseData"); } } });

No comments:

Post a Comment

Post Code on Blogger

Simplest way to post code to blogger for me: <pre style="background: #f0f0f0; border: 1px dashed #CCCCCC; color: black;overflow-x:...