Javascript JSON-WSP Client not working

Asked by oyzzo on 2012-10-18

Hi,

I'm trying to use the json-wsp javascript client but i'm not getting it to work.
the example at http://www.ladonize.org/index.php/Python_Example#Example_1 is not working neither, i've tried with chrome and firefox but with both i get the disabled inputs even after clicking the "Load Example 1" button.

This is the code i am using to test the loading of the description:
http://pastebin.com/tBXFa2nZ

Maybe i'm doing something wrong, it'd be very nice to have an example of the javascript json-wsp client :)

thanks!
oyzzo

Question information

Language:
English Edit question
Status:
Solved
For:
ladon Edit question
Assignee:
No assignee Edit question
Solved by:
oyzzo
Solved:
2012-10-19
Last query:
2012-10-19
Last reply:
2012-10-18
jsgaarde (jakob-simon-gaarde) said : #1

As you can see in the example at ladonize.org it does in fact work. That's no simulation :-)

What you are experiencing is a browser security limitation for AJAX requests. By default you can not send AJAX requests to a different domain. So if your service is not running on the same domain as your website, you need to setup a webserver proxy configuration, so that if ie. your site domain is "your.domain.com" http://your.domain.com/service should target http://ladonize.org/python-demos/

1. Setting up a reverse proxy on IIS:
http://technet.microsoft.com/en-us/library/ee215194(v=ws.10).aspx

You should have a match rule looking something like this:

<rule name="Reverse Proxy to MV-ID Services" stopProcessing="true">
  <match url="^service/(.*)" />
  <action type="Rewrite" url="http://ladonize.org/python-demos/{R:1}" />
</rule>

2. Setting up a reverse proxy on Apache2:
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

In your apache site-configuration you should have something like this in the site configuration:

ProxyPass /service https://mvid-services.mv-nordic.com/v1
ProxyPassReverse /service https://mvid-services.mv-nordic.com/v1

/ Jakob

jsgaarde (jakob-simon-gaarde) said : #2

As you can see in the example at ladonize.org it does in fact work. That's no simulation :-)

What you are experiencing is a browser security limitation for AJAX requests. By default you can not send AJAX requests to a different domain. So if your service is not running on the same domain as your website, you need to setup a webserver proxy configuration, so that if ie. your site domain is "your.domain.com" http://your.domain.com/service should target http://ladonize.org/python-demos/

1. Setting up a reverse proxy on IIS:
http://technet.microsoft.com/en-us/library/ee215194(v=ws.10).aspx

You should have a match rule looking something like this:

<rule name="Reverse Proxy to MV-ID Services" stopProcessing="true">
  <match url="^service/(.*)" />
  <action type="Rewrite" url="http://ladonize.org/python-demos/{R:1}" />
</rule>

2. Setting up a reverse proxy on Apache2:
http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

In your apache site-configuration you should have something like this in the site configuration:

ProxyPass /service http://ladonize.org/python-demos
ProxyPassReverse http://ladonize.org/python-demos

/ Jakob

oyzzo (oyzzoforfree) said : #3

Thanks for your quick answer, this pointed me to the right direction,

Adding this line to my apache configuration did solve the cross origin reference problem:
 Header set Access-Control-Allow-Origin "*"

Now loading the description works, but calling the add service doesn't work, i've checked the sources for the example at ladonize.org and my code is exacly the same so i cannot find where the problem is... The server is working fine so i'm pretty sure now the problem has to be on the client.
here is a paste of the test code:

http://pastebin.com/qxzQFYZ0

jsgaarde (jakob-simon-gaarde) said : #4

I use the javascript client all the time so of course it works. What does firebug say?

oyzzo (oyzzoforfree) said : #5

When i say the client, i mean my code, so i guess i'm doing something wrong.
I've traced a little bit with firebug and it looks like the call is made correctly but nothing is returned

jsonwsp_desc is filled right
jsonwsp_req is created right too
but after callMethod calls postRequest, req.responseText is [ ]

and the code inside function(resp) is not being executed

oyzzo (oyzzoforfree) said : #6

Hum, i did mess something while inspecting the code... with a fresh copy of the .js downloaded it works perfect :)

Sorry and thanks a lot!