Closed Bug 736906 Opened 12 years ago Closed 8 years ago

Using jquery within a javascript does not return json results.

Categories

(Core :: DOM: Core & HTML, defect)

11 Branch
x86_64
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED INVALID
Tracking Status
platform-rel --- ?

People

(Reporter: aevargareg, Unassigned)

References

()

Details

(Whiteboard: [platform-rel-jQuery])

Attachments

(1 file, 1 obsolete file)

When I fire an onclick event to get JSON data, "object XMLData" is returned instead of the data.  This procedure works correctly in IE9 and Opera 11.61.

I validated my JSON data at
http://jsonlint.com/
http://jsonformatter.curiousconcept.com/

You will need a copy of jquery.min.js (version 1.7.1) to test this, as well as my files below.



HTML file
=========
<!DOCTYPE html> 

<html lang="en">

<head>
    <title>Firefox jQuery test page</title>
    <meta charset="utf-8"/>
    <meta name="author" content="Alan Varga"/>
    <meta name="description" content="demonstrate bug in Firefox jquery get"/>
    <meta http-equiv="last-modified" content="Sun, 18 Mar 2012 12:20 CDT"/>

    <style>
#testlink {
    color: Blue;
    background-color: LightGreen;}
    </style>

    <script src="jqtest.js"></script>
    <script src="jquery.min.js"></script>
</head>


<body>

<p>
Click
    <span id="testlink">
        <a title="popup hint for link"
	   onclick="showFile();">here</a>
    </span>
to display the contents of the json file in an alert window.
</p>

<p>
In Firefox 11, [object XMLDocument] displays instead of the actual file.<br/>
Internet Explorer 9 and Opera 11.61 the file displays, as expected.

</body>
</html>



JSON datafile
=============
{"submenus":
    {"submenu":[
       {"name": "submenu1",
        "item": "test1"},

       {"name": "submenu7",
        "item": "test7"}]
    }
}
showFile() isn't defined in your testcase, and neither is jqtest.js.
Component: File Handling → Untriaged
QA Contact: file.handling → untriaged
Sorry, I copied my HTML from the wrong open window.  Try this one instead, which includes showFile() directly in the HTML:


<!DOCTYPE html> 

<html lang="en">

<head>
    <title>Firefox jQuery test page</title>
    <meta charset="utf-8"/>
    <meta name="author" content="Alan Varga"/>
    <meta name="description" content="demonstrate bug in Firefox jquery get"/>
    <meta http-equiv="last-modified" content="Mon, 19 Mar 2012 08:00 CDT"/>

    <style>
#testlink {
    color: Blue;
    background-color: LightGreen;}
    </style>

    <script src="jquery.min.js"></script>

    <script>
function showFile(){
    $.get("jqtest.json", function(data){
    alert(data);
    });
}
    </script>
</head>



<body>

<p>
Click
    <span id="testlink">
        <a title="popup hint for link"
	   onclick="showFile();">here</a>
    </span>
to display the contents of the json file in an alert window.
</p>

<p>
In Firefox 11, [object XMLDocument] displays instead of the actual file.<br/>
In Internet Explorer 9, Opera 11.61 and Chrome 17.0 the file displays, as expected.

</body>
</html>
Summary: Using jquery within a javascript does not json results. → Using jquery within a javascript does not return json results.
Attached file Reporter's test case (obsolete) —
Attachment #607370 - Attachment is obsolete: true
I get no alert with Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20120319 Firefox/14.0a1 ID:20120319031122 on attachment 607372 [details] - no errors in error console
The testcase required the json file as well. http://www.joshmatthews.net/json.html is the same testcase, and it passes in Firefox nightly. I suspect this bug has been fixed between FF 11 and nightlies. Alan, can you confirm?
I installed Mozilla/5.0 (Windows NT 6.1; WOW64; rv:14.0) Gecko/20120319 Firefox/14.0a1.

I have to say this is still unresolved, as my alert still shows [object XMLDocument], instead of the actual data.
Is that with my testcase? What if you try safe mode?
WFM with Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20120319 Firefox/14.0a1 ID:20120319031122
That's the funny thing... After I retried my test case, which failed, I clicked on your link, and it passed.  I thought it might be because you had a different URL for jquery.min.js, or that my local file was cached, so I changed my URL to the googleapis.com link and cleared my browsing history for the last hour.  Your testcase works and mine doesn't.

I'm now back to
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0
and your testcase works and mine doesn't.  This is the way my day has been going.  If you have an explanation, I'd appreciate the education.  Otherwise, I think you can close this bug report, since you've demonstrated that there isn't an issue.
One further follow-up: I saved the source from your link as a local file, opened it and it failed.

Further, I uploaded my testcase, data and a my copy of jquery.min.js to my own webspace, opened it and it passed!  Give it a try:

http://user.mc.net/~aevarga/tests/FF%20bug/jqtest.htm

So it seems that the jQuery functionality is only working if the page is loaded from the Internet.
That's an excellent datapoint, thanks. This probably has to do with XHRs and file:// URLs.
Component: Untriaged → DOM
Product: Firefox → Core
QA Contact: untriaged → general
Well, for file:// URIs we will always attempt to parse them as XML, since there is no MIME information for local files.

It sounds like whatever you're doing in your jquery code is trying to pick up the responseXML instead of the responseText for some reason.
I was using this mechanism for debugging, but it isn't critical.  My data is JSON, but if I infer correctly, I wouldn't have had a problem if I were using XML data instead.

You can close this incident, since this is expected behavior I didn't know about.  Thanks for investigating.
Whiteboard: [platform-rel-jQuery]
platform-rel: --- → ?
Closing per Comment #14.
Status: UNCONFIRMED → RESOLVED
Closed: 8 years ago
Resolution: --- → INVALID
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: