ajax - dojo.io.script.get vs dojo.xhrGet -
i have spent days working on , feel dumb. have been working on demos , samples never work when try locally own url. have web service returns results in json , trying call using dojo , view results. took search google example , substituted url , parameters. perhaps still not understand basics so: - io.script.get vs xhrget if using cross domain urls better use io.script.get? correct? callbackparam? function being called in webservice? webservice url follows: http://xxx.xxx.x.xxx/wcfservices/wcfinstance/service1.svc/retrievdata?query=word
when use following code nothing displayed.
function searchgoogle() { // node we'll stick text under. var targetnode = dojo.byid("rules"); // parameters pass xhrget, url, how handle it, , callbacks. var jsonpargs = { url: "http://xxx.xxx.x.xxx/wcfservices/wcfinstance/service1.svc/retrievedata?", callbackparamname: "callback", content: { query:"dojowords" }, load: function (data) { // set data search viewbox in nicely formatted json targetnode.innerhtml = "<pre>" + dojo.tojson(data, true) + "</pre>"; }, error: function (error) { targetnode.innerhtml = "an unexpected error occurred: " + error; } }; dojo.io.script.get(jsonpargs); } dojo.ready(searchgoogle); here webservice results like:
"{\"rules\":[{\"value\":\"allstate\"}, {\"value\":\"cidade de goa beach\"},{\"value\":\"euro 2012\"}, {\"value\":\"euro2012\"},{\"value\":\"european&championship\"}, {\"value\":\"holiday inn resort\"}, {\"value\":\"holiday inn resort goa\"}, {\"value\":\"hotel goa\"},{\"value\":\"hyatt goa\"},{\"value\":\"i buy car\"},... if part correct @ least know have data can bind datagrid or chart.
dojo.io.script.get cross domain requests. xhrget same domain requests.
dojo.io.script.get uses hack expects jsonp or json padding result. wraps response of web service call inside self executing function. function name callback name. has wired before call knows defined function call when response comes back.
all of arguments documented http://dojotoolkit.org/reference-guide/1.7/dojo/io/script.html
my guess why service isn't working because wrote web service , not handle jsonp. not wrapping response inside callbackparamname.
your results should like
callback({json}); where callback whatever set in callbackparamname
you can remove ? url, should handled you.
Comments
Post a Comment