INFO 344 Web Tools And Development CK Wang University of Washington Spring 2014
Cross Domain Scripting http://uwinfo344.chunkaiw.com/getOneLessThanN.php?n=11 Simple PHP script, 3 lines of code http://uwinfo344.chunkaiw.com/oneless.html It works! Download html file, run locally (different domain) doesn’t work Browser blocks cross domain AJAX
Why? Security!! If we allowed cross domain scripting Imagine Go to www.wellsfargo.com Download their html files Host those files on www.evilsite.com Get users to login! AND now I can do anything with their data & account!
JSONP JSON with Padding Use <script> tag Pass a call back function <script> will have function(data)
JSONP Open Visual Studio, C# Web Application, Empty Add new ASMX web service Implement WebMethod for getOneLessThanN(int n) Add http get/post to web.config Uncomment script services & add script method/response format = JSON, need to clear context to remove meta data Publish on Azure! (as a web site)
JSONP Create jsonp.html, add <script> to your service, for example: updateResults is your callback <script> to your service will generate javascript that calsl your callback function
JSONP Part 2! Write a version using jQuery. http://stackoverflow.com/questions/14221429/how-can-i-produce-jsonp-from-an-asp-net-web-service-for-cross-domain-calls Part 3: How would you write your own JSONP wrapper? i.e. implement this ajax jsonp call?
Reading http://stackoverflow.com/questions/2067472/what-is-jsonp-all-about
Questions?