jquery - Does Google not accept ajax in Spreadsheets? -


i'm trying data both jquery .get , xmlhttprequest, seems both of them fail.

i'm trying in modal dialog created in spreadsheet.

is there wrong, or procedure must before trying?


details:

1 - modal dialog working (the messages put before ajax code shown fine, messages after .get fine.
2 - know google urlfetch in server-side, i'm interested in client-side now.


code:

1 - jquery get:

alert("test");  $.get("http://www.w3schools.com/jquery/demo_test.asp", function(data,status){             alert(status + " /// " + data); //never shown      });  alert("after get"); //shown 

2 - httprequest:

var req = new xmlhttprequest(); var url2 = "http://www.w3schools.com/ajax/ajax_info.txt"; req.open('get', url2, false); alert("got2"); req.send(); alert("sent2");  //never shown  alert(req.responsetext); //never shown 

i assume using custom html code in modal dialogs?

there's no problem javascript code far can tell, xmlhttprequest (and in turn jquery.get, since relies on xmlhttprequest interally) failing because of permissions problems. can see errors in developer console of browser.

first, google spreadsheets loaded using https, , (at least chrome tested) not allowed load insecure http resource https page via xmlhttprequest (the idea that, if endpoint insecure, cannot guarantee whatever data obtain via xmlhttprequest not malicious attacker has inserted, instead of actual data).

second, xmlhttprequest restricts same domain, default. means can access resources on domain [some random string].googleusercontent.com script code loaded from. perform xmlhttprequest domain (called cross-origin xmlhttprequest) server providing resource must send special http headers indicating server permits such cross-origin access. more details here: https://developer.mozilla.org/en-us/docs/web/http/access_control_cors. unless w3schools server sends correct headers, can't use xmlhttprequest on urls.

thus if want access resource, need ensure served on https , sending correct headers. example of resource both above correctly yahoo query language endpoints. using following url work, example:

https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3d'http%3a%2f%2fen.wikipedia.org%2fwiki%2fyahoo'%20and%20xpath%3d'%2f%2ftable%2f*%5bcontains(.%2c%22founder%22)%5d%2f%2fa'&format=json&env=store%3a%2f%2fdatatables.org%2falltableswithkeys 

alternatively, access resource using google's servers via urlfetch!


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -