3

what's weird about my error is that it ONLY occurs in the firefox extension I have linked to at the bottom of this post. I cannot reproduce this error in any other setting.

I have this ajax request

$.ajax({
  type: "GET",
  dataType: "jsonp",
  url: url,
  jsonpCallback: "JSONCallback",
  data: {title:$("#txtTitle").val(), url:taburl},
  success: function(data, textStatus) {
    if(data.code > 0)
        {
        $("#icon").removeClass().addClass('accept');
        }
    else
        {
        $("#icon").removeClass().addClass('error');
        if(data.code == '-1')
            alert('kunne ikke finde din ønskeseddel på e-ønsker.dk - besøg e-ønsker.dk, og prøv derefter igen');
        }
  },
  error: function(xhr, textStatus, errorThrown) {
     alert("XMLHttpRequest="+xhr.responseText+"\ntextStatus="+textStatus+"\nerrorThrown="+errorThrown);
    $("#icon").removeClass().addClass('error');
  }
});

server returns

JSONCallback({"code":405});

headers are application/json

so why am I getting a parseError saying JSONCallback was not called? I thought jQuery was supposed to handle that for me?

the code is from http://builder.addons.mozilla.org/addon/1022928/latest and the file in question is data/panel.js

Rob W
  • 341,306
  • 83
  • 791
  • 678
Jakob
  • 4,784
  • 8
  • 53
  • 79
  • This code actually works well. You can test it with jsfidlle - here is the Fiddle I created to test your code: http://jsfiddle.net/eW6XR/ Maybe the server should return the _ parameter? – zopieux Nov 01 '11 at 22:53
  • @Zopieux - Can I get you to try out this extension https://builder.addons.mozilla.org/addon/1022928/latest/ then, and tell me if (when you hit "Gem" and the ajax call is executed it works for you? – Jakob Nov 01 '11 at 23:13
  • I can't get your extension to work because your server returns a 500: `

    Error Number: 1048

    Column 'uid' cannot be null

    INSERT INTO 'default_wishlist' ('text', 'position', 'uid', 'url') VALUES ('some test', 1, NULL, 'http://tinyurl.com/36lneem')

    `
    – zopieux Nov 01 '11 at 23:59
  • @Zopieux - sorry the plugin requires that you've visited http://xn--e-nsker-r1a.dk/ once – Jakob Nov 02 '11 at 10:04
  • It may be that this error is actually firefox-extension dependant – Jakob Nov 02 '11 at 12:19
  • 1. You are doing two alternatives together - defining a named callaback 'JSONCallback as well as defining an anonymous callback when you define 'success'. You should do only one of them. 2. I suggest you go for anonymous callback and make sure that your server takes the callback name from the GET request and then return "(' – JV. Nov 13 '11 at 10:45
  • @JV - I have tried leaving out the jsonpcallback, but that unfortunately doesn't solve the problem – Jakob Nov 13 '11 at 15:49
  • 1. do you own the server side code too? or not? 2. If you own it, what is it, Python/django or something else? 3. Not sure but that 405 might just stand for HTTP405, which means that the method cross domain 'GET' is not allowed by the server. Usually if the server responds with Http405 it sends in a list of options [methods allowed]. Can you check the exact response code form server and text status sent back? – JV. Nov 13 '11 at 17:07
  • JV - yes I own it. - It is php. The 405 is just the id of the newly inserted item. It means that the serverside is working as it should. The statuscode is 200. It's just as it should be, and in all other cases than in the firefox extension, the response gets interpreted correctly as a successfull ajax call, but for some reason on in ff extension – Jakob Nov 13 '11 at 17:17
  • hmmm... well, I can help you debug it, if you want. we can use chat http://chat.stackoverflow.com/ or github (if the code is opensource) or some other way you suggest. (tomorrow or later) – JV. Nov 13 '11 at 18:12
  • that would be really great! The code is available at https://builder.addons.mozilla.org/addon/1022928/latest/ I haven't got it anywhere on my pc, so I suggest we debug it from there :) – Jakob Nov 13 '11 at 18:20
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/4954/discussion-between-jv-and-jakob) – JV. Nov 13 '11 at 18:41

3 Answers3

2

The problem is with window. The easiest way to fix this will be to edit the jQuery code (I know, I hate doing this too) to use unsafeWindow rather than window.

gkoberger
  • 476
  • 4
  • 11
  • I had to actually do a search and replace, and switch every reference to `window` over to `unsafeWindow`. – gkoberger Nov 17 '11 at 20:59
  • I'm editing 1.6.4 replacing every instance of window with unsafeWindow, but that breaks the jQuery code for me, saying that $ is not defined – Jakob Nov 17 '11 at 21:31
  • do you have a reference to your modified jquery code, maybe I can just use that? – Jakob Nov 20 '11 at 16:54
  • Here's what I've been using, with no issues so far: https://github.com/gkoberger/BugzillaJS/blob/master/includes/jquery.js – gkoberger Nov 20 '11 at 20:23
  • 1
    U GENIUZZZ DAWWWGGGG - DAT IS JUST GENjUZZZ thanks man. I've had so many people involved that couldn't figure out what on earth was wrong. – Jakob Nov 20 '11 at 22:59
1

have you tried to enable the"Cross-Origin Resource Sharing"

using : jQuery.support.cors = true;

i had the same issue with firefox a while ago and using that line before making my ajax call fixed it for me.

i coulnd get your fizzle to work for some reason :) good luck

Lil'Monkey
  • 991
  • 6
  • 14
0

This isn't really an answer, but why are you using jsonp? Code running in the context of a Firefox extension isn't subject to the cross origin restriction.

My understanding of jsonp is that a script tag is added to the document using the server's response so that your callback is executed. In a Firefox extension "document" is the XUL UI not the regular page's document. I'm not sure that adding a script element to XUL will cause the browser to execute that script.

Hope this helps!

erturne
  • 1,799
  • 1
  • 15
  • 29
  • I get a domain related error if I don't use JSONP. My request simply doesn't hit my host. With this JSONP it does hit my host, and actually gets a 200 response, it just never fires. It probably is an issue with adding the script tag, i just don't know how to fix it. – Jakob Nov 13 '11 at 00:32