📜 ⬆️ ⬇️

Cross Domain AJAX based on CSS

Recently encountered a problem how to transfer data from server A to
javascript on server B, if server server code cannot be written on server B,
and on A you can.
And I found an elegant solution .
The essence of the solution is that an object is proposed for use.
CSSHttpRequest, which provides CSS-based AJAX requests. it
works because CSS does not have security restrictions
standard XMLHttpRequest object.
In contrast, JSONP has a restriction only on GET requests. There are also some browser compatibility issues.
The code looks like this.
  CSSHttpRequest.get (<br> "http://www.nb.io/hacks/csshttprequest/hello-world/", <br> function (response) {alert (response);} <br>); 

Data is encoded on the server in the form of 2-kilobyte chains. Answer
returns in the form:
  # c0 {background: url (data:, Hello% 20World!);  } <br> # c1 {background: url (data:, I'm% 20text% 20encoded% 20in% 20CSS!);  } <br> # c2 {background: url (data:, I% 20like% 20arts% 20and% 20crafts.);  } 

On server B using javascript creates an invisible iframe, in which
and loads CSS.
This also works in XHTML.

This solution is compatible with IE6 +, Firefox 2+, Safari 3+, iPhone.
License Type: Apache License

')

Source: https://habr.com/ru/post/87826/


All Articles