genia.likes.science@gmail.com | c5f82a2 | 2013-05-08 02:44:35 -0700 | [diff] [blame] | 1 | <!doctype html> |
| 2 | <html> |
| 3 | <head> |
| 4 | <title>easyXDM</title> |
| 5 | <script type="text/javascript" src="../easyXDM.debug.js"> |
| 6 | </script> |
| 7 | <script type="text/javascript"> |
| 8 | /** |
| 9 | * Request the use of the JSON object |
| 10 | */ |
| 11 | easyXDM.DomHelper.requiresJSON("../json2.js"); |
| 12 | </script> |
| 13 | <script type="text/javascript"> |
| 14 | // this is only bootstrapping code |
| 15 | var REMOTE = (function(){ |
| 16 | var remote = location.href; |
| 17 | switch (location.host) { |
| 18 | case "provider.easyxdm.net": |
| 19 | location.href = remote.replace("provider", "consumer"); |
| 20 | break; |
| 21 | case "easyxdm.net": |
| 22 | remote = remote.replace("easyxdm.net", "consumer.easyxdm.net"); |
| 23 | break; |
| 24 | case "consumer.easyxdm.net": |
| 25 | remote = remote.replace("consumer", "provider"); |
| 26 | break; |
| 27 | case "xdm1": |
| 28 | remote = remote.replace("xdm1", "xdm2"); |
| 29 | break; |
| 30 | } |
| 31 | return remote.substring(0, remote.lastIndexOf("/")); |
| 32 | }()); |
| 33 | |
| 34 | // this is really what you are after |
| 35 | var xhr = new easyXDM.Rpc({ |
| 36 | local: "../name.html", |
| 37 | swf: REMOTE + "/../easyxdm.swf", |
| 38 | remote: REMOTE + "/../cors/", |
| 39 | remoteHelper: REMOTE + "/../name.html" |
| 40 | }, { |
| 41 | remote: { |
| 42 | request: {} |
| 43 | } |
| 44 | }); |
| 45 | |
| 46 | function getGlossary(){ |
| 47 | xhr.request({ |
| 48 | url: "../example/glossary.aspx", |
| 49 | method: "POST", |
| 50 | headers: { |
| 51 | "x-auth-token": "abcde" |
| 52 | }, |
| 53 | data: { |
| 54 | param1: "a", |
| 55 | param2: "b" |
| 56 | } |
| 57 | }, function(rpcdata){ |
| 58 | var json = easyXDM.getJSONObject().parse(rpcdata.data); |
| 59 | |
| 60 | document.getElementById("response").innerHTML = json.glossary.title; |
| 61 | document.getElementById("header").innerHTML = rpcdata.headers["x-foo"]; |
| 62 | }); |
| 63 | |
| 64 | } |
| 65 | </script> |
| 66 | </head> |
| 67 | <body> |
| 68 | <div style="border:1px solid black;padding:3px;margin:10px;"> |
| 69 | <a href="index.html">Index of examples</a> |
| 70 | | <a href="http://github.com/oyvindkinsey/easyXDM/#readme">Readme at github</a> |
| 71 | | |
| 72 | | <a href="http://easyxdm.net/">easyXDM.net</a> |
| 73 | | <a href="http://groups.google.com/group/easyxdm">easyXDM at Google Groups</a> |
| 74 | <br/> |
| 75 | The examples are executing slower than the production build due to the extensive tracing. |
| 76 | <br/> |
| 77 | If you are alerted about a popup, then this is only the trace log feature. You can ignore this. |
| 78 | </div> |
| 79 | <script type="text/javascript"> |
| 80 | document.write("Domain: " + location.host); |
| 81 | </script> |
| 82 | <!-- easyXDM.Debug.trace(msg) will output its messages to any element with the id "log" --> |
| 83 | <div id="log" style="height:100px;border:1px dotted black;overflow:auto"> |
| 84 | </div> |
| 85 | <div id="embedded"> |
| 86 | </div> |
| 87 | <div> |
| 88 | This example shows how to use easyXDM to call regular ajax/cors services (no JSONP) from remote domains. |
| 89 | <br/> |
| 90 | <input type="button" onclick="getGlossary()" value="Call getGlossary using the exposed method"/> |
| 91 | <br/> |
| 92 | Data from response:<span id="response"></span> |
| 93 | <br/> |
| 94 | Data from header:<span id="header"></span> |
| 95 | </div> |
| 96 | <script type="text/javascript"> |
| 97 | var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www."); |
| 98 | document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E")); |
| 99 | </script> |
| 100 | <script type="text/javascript"> |
| 101 | if (location.host.indexOf("easyxdm.net") !== -1) { |
| 102 | try { |
| 103 | var pageTracker = _gat._getTracker("UA-9535591-3"); |
| 104 | pageTracker._setDomainName(".easyxdm.net"); |
| 105 | pageTracker._trackPageview(); |
| 106 | } |
| 107 | catch (err) { |
| 108 | } |
| 109 | } |
| 110 | </script> |
| 111 | </body> |
| 112 | </html> |