Bug Tracker

Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#14524 closed bug (notabug)

jQuery's Ajax interferes after adding jQuery script to an inner iframe

Reported by: anonymous Owned by: anonymous
Priority: undecided Milestone: None
Component: unfiled Version: 1.10.2
Keywords: Cc:
Blocked by: Blocking:


In this example, attempting to jQuery.ajax or jQuery.get causes the outer window's jQuery variable to get replaced - the jQuery.dialog and any other plugins to jQuery are no longer there. (It happens in 1.9.1 and 1.10)

    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

Try and <button id="btn">load</button>
<iframe width=300 height=300></iframe>

"use strict";
    var $ = jQuery;
    console.log(typeof jQuery('iframe').dialog);
    var doc = jQuery('iframe')[0].contentDocument;
    function insertscript(src) {
        var newscript = doc.createElement('script');
    //This breaks the jQuery:
    var test = $.get('',function(){
        //Now we know jQuery should be in the frame.
    //So does this:
    console.log(typeof jQuery('iframe').dialog);
        //jQuery is no longer the original jQuery object. Note the cached reference $().dialog does exist though.
        console.log('after awhile... dialog is ' + typeof jQuery('iframe').dialog);

Change History (6)

comment:1 Changed 9 years ago by m_gol

Owner: set to anonymous
Status: newpending

What is this bug about? Why are you downloading a second copy of jQuery via the first one?

comment:2 Changed 9 years ago by anonymous

Status: pendingnew

Looks like the real bug here is that jQuery.ajax documentation mentions that the fetched data will be run, if it is a script, but jQuery.get has no mention of this. This should be a big bold item in my opinion, people will wonder why it's immediately running the script, especially if it only does so same-domain.

comment:3 Changed 9 years ago by dmethvin

Resolution: notabug
Status: newclosed

Notice that the first thing the jQuery.get)() docs do is tell you the equivalent jQuery.ajax() call. So, an astute reader could know that they need to read those docs. Or we could copy and duplicate a big chunk of docs into the ajax shorthand methods but that just makes maintenance harder.

comment:4 Changed 9 years ago by scottgonzalez

Or we could copy and duplicate a big chunk of docs into the ajax shorthand methods but that just makes maintenance harder.

We already have a solution for that problem: XML Includes.

comment:5 Changed 9 years ago by dmethvin

Now break up all the ajax options and discussion text into include-able parts and determine which are applicable for each of the .get/.post/.load shortcut methods.

comment:6 Changed 9 years ago by anonymous

Yeah that explains a lot

Note: See TracTickets for help on using tickets.