1
$.getJSON('http://www.thesite.net/api.php', function(data) {
    if (data.status != 401)
    {
        if (data.messages == 0)
        {
            $('#messages').html('No New Messages');
        }
        else
        {
            $('#messages').html(data.messages + ' new messages. <a href="javascript:go_to_messages();">Check</a>');
        }
        $('#currency').html(data.cashfmt + '  Bux');
    }
    else
    {
        $('#container').html('You are not logged into the site. Please <a href="javascript:go_to_login();">login</a>.');
    }
});

This is the code that I have with a few small modifications. It is surrounded by the tags in an HTML document. It is to be used in an extension. It works perfectly in Chrome when I make the extension and use it but in the same document in Opera, and I have checked multiple times, this is the cause of the problem. The page remains unedited after it runs. The rest of the page is very simply, with very little JS. There are no Chrome-specific methods. For some reason this isn't working in Opera. I tried adding a line to check if maybe it was just ignoring the ifs, but I found that it even ignores lines placed after the first line(It worked perfectly in Chrome when I did this) Does Opera not accept getJSON?

TimeCoder
  • 1,379
  • 3
  • 12
  • 13

1 Answers1

0

Does GetJSON Work in Opera?

Yes.

If you need cookie sharing, add this line to your extension's config.xml:

<feature name="opera:share-cookies" required="true"/>

Also in your extension's config.xml, you need to specify the access origins for the domains that you want to access.

For testing purposes, you can temporarily use:

<access origin="*"/>

However, you should be more explicit and should use this:

<access origin="http://thesite.net/" subdomains="true"/>
<access origin="https://thesite.net/" subdomains="true"/>

jQuery solution 1:

Use JSONP.

$.getJSON("http://www.thesite.net/api.php?callback=?", function (data)
{
    ...
});

Link to documentation:

http://api.jquery.com/jQuery.getJSON/#jsonp

jQuery solution 2:

As of jQuery 1.5, you have to force cross-site scripting.

$.support.cors = true;

or

jQuery.support.cors = true;

See this answer:

jQuery Call to WebService returns "No Transport" error

Community
  • 1
  • 1
XP1
  • 6,910
  • 8
  • 54
  • 61