unable to do a cross domain http request

Forums » General Opera topics » Opera Widgets

You need to be logged in to post in the forums. If you do not have an account, please sign up first.

Go to last post

6. April 2010, 01:42:24

shailesh41

Posts: 9

unable to do a cross domain http request

Hi,

I am unable to get the cross domain http request working. Also unable to debug on localhost as well.

I have also set network attribute to public in the config.xml

Using the following configuration of opera
Version
10.51

Build
3315

Platform
Win32

System
Windows XP

Any help is appreciated.

Thanks,
Shailesh.

7. April 2010, 08:58:53

Opera Software

lowik

Posts: 41

I checked photo editor widget (go to "Help" -> "Send us a message") with exactly the same build and everything seems to be all right. Maybe the problem is with your JavaScript code? Can you dpaste it ?

7. April 2010, 19:30:39

shailesh41

Posts: 9

Thanks Iowik.
I am doing a simple ajax GET request.

window.onload = init;

function init(){
    canvas = document.getElementById('canvas');
    context2D = canvas.getContext('2d');
    context2D.fillStyle = '#000';
    context2D.fillRect(0,0,canvas.width,canvas.height);
    
    
    var req = new XMLHttpRequest();
    var uri = "http://www.google.com";
    req.open('GET', uri, true);
    req.onreadystatechange = function(){
        if (req.readyState == 4) {
            if (req.status == 200) {
                alert('success');
            }
            else {
                alert('error');
            }
        }
    };
    req.send(null);
}


I keep getting the security violation error.
JavaScript - widget://wuid-4bbca597-c485-0eea-0b65-24c7c4cd9b36/index.html
Error thrown at line 26, column 4 in init() in widget://wuid-4bbca597-c485-0eea-0b65-24c7c4cd9b36/script/main.js:
req.send(null);
Uncaught exception: ReferenceError: Security violation


and this is my config.xml file

<?xml version='1.0' encoding='UTF-8'?>
<widget dockable="yes" network="public">
  <widgetname>Simple Test</widgetname>
  <description>testing ajax</description>
  <width>1024</width>
  <height>768</height>
  <icon>images/icon.png</icon>
  <author>
    <name>Shailesh</name>
  </author>
  <security>
    <access>
      <protocol>https</protocol>
      <protocol>http</protocol>
	  <host>google.com</host>
	</access>
  </security>
</widget>



Have also attached the widget.
Am not sure what am I doing wrong here :-(

simple_test.wgt

7. April 2010, 20:08:10

Dodwin

Posts: 36

You wrote <host>google.com</host> but you mean <host>www.google.com</host>

Better leave the <security> tag out, then you have access to every site.
Only if you specify a host the widget will be limited to the given hosts.

An example is that if the host element is missing, the widget is requesting access to all hosts.

Opera Widgets specification 1.0, fourth edition, 4.13 The access element

8. April 2010, 21:05:32

shailesh41

Posts: 9

Thanks a lot Dodwin.
Works great without the security tags or
security tags with "www" added

was blind folded in following different articles :-). All examples in those seem to leave out "www" though






9. April 2010, 17:32:59

shailesh41

Posts: 9

Has anybody got the cross domain ajax request working inside YUI?

The same code when I use it inside YUI leads to the security violation

12. April 2010, 02:03:25

shailesh41

Posts: 9

Working fine now. The widget installation was kind of corrupt. It always seemed to pick up the old code. dont know why?
Had to create a new project and everything seemed to work fine. :-)

Forums » General Opera topics » Opera Widgets