Search code examples
javascriptdesire2learnvalence

Does Valence javascript client libary work on localhost?


I've been experimenting with the Valence javaScript client library and the 'GettingStartedSample' download from D2L.

If the sample files are uploaded, accessed and ran from within a D2L course site the script works, however, if I try to run it from a localhost I run into a problem. On localhost I can successfully authenticate the application however when I try to run a 'Get Versions' or 'WhoAmI' request nothing happens.

Firebug tells me the following:

  • Object { readyState=0, status=0, statusText="error" } server.js (line 77)
  • error server.js (line 78)
  • (an empty string) (line 79)

Should I be able to make a request using the javascript client library from a localhost?


Solution

  • The short answer is yes, but you need to do some additional work.

    I would advise reading up on the same origin policy so you have some background as to why XHRs (in your case, Valence calls) between domains do not work out of the box. The easiest thing to do is to use jsonp if all you are making are GET requests. If you need to make other requests, you will need to look into getting CORS support set up on your instance.