how to read json response from cloudify rest api using jquery? -
i need fetch json data cloudify rest url (remotehost) http://hostname:8100/service/applications/
.
this url returns following json response:
{ "response": { "petclinic": "" }, "status": "success" }
i've tried response code below:
$.getjson("http://hostname:8100/service/applications?jsoncallback=?", function (result) { $.each(result, function (i, field) { $("div").append(field + " "); }); });
i checked request net panel in firebug, showing 200 ok status, can't json data. error bellow appears in console:
same origin
assuming call made same domain (e.g. you're deploying local cloud, , call made locally, , sends request localhost:8100
), should able succeed performing rest calls, provided remove ?jsoncallback=?
request url.
this suffix url serves request wrapper function on response, , used jsonp (javascript-object-notation padding) type requests. in order use jsonp server must support - cloudify rest api not - such requests fail, origin.
cross origin
if you're trying run different domain of rest server, won't work regardless. rest api not allow cross origin resource sharing either. meant use servers, create service makes calls rest api , serve client that. can put jquery xhr calls on client, calling own service.
further reading
- json jsonp: bypass same origin policy on codeproject.com
- http access control on mozilla developer network
- the cloudify docs on clodifysource.org
Comments
Post a Comment