How to access the web service in html page? Static site? -
accessing web service in html pages, have static site want access 1 web service in site.
if running static site assume webservice want access not on same domain , cannot set proxy on server side. if both assumptions correct cannot use "ordinary" ajax because of same origin policy in browser. best bet may jsonp supported many webservices.
i give simple example. retrieve value stored under key "mykey" openkeyval storage webservice in javascript jquery, call
$.ajax({ url: "http://api.openkeyval.org/mykey", datatype: "jsonp", success: function(data){ // data } });
and store value, call
$.ajax({ url: "http://api.openkeyval.org/store/", data: "mykey=myvalue", datatype: "jsonp", success: function(data){ // value has been succesfully saved } });
please note nowadays many people consider cross-origin resource sharing (cors) better alternative jsonp. however, may bit harder started you.
Comments
Post a Comment