Skip to main content

Bug Tracker

Side navigation

#14524 closed bug (notabug)

Opened November 08, 2013 01:50AM UTC

Closed November 16, 2013 02:33AM UTC

Last modified December 19, 2013 11:37PM UTC

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:
Description

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)

<html>
<head>
    <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>
</head>
<body>

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

<script>
"use strict";
jQuery('#btn').click(function(){
    var $ = jQuery;
    console.log(typeof jQuery('iframe').dialog);
    var doc = jQuery('iframe')[0].contentDocument;
    function insertscript(src) {
        var newscript = doc.createElement('script');
        newscript.setAttribute('src',src);
        doc.documentElement.appendChild(newscript);
    }
    insertscript('http://192.168.1.17/wordpress/wp-includes/js/jquery/jquery.js');
   
    //This breaks the jQuery:
    var test = $.get('http://192.168.1.17/wordpress/wp-includes/js/jquery/jquery.js',function(){
        //Now we know jQuery should be in the frame.
    });
   
    //So does this:
    //jQuery.ajax({url:'http://192.168.1.17/wordpress/wp-includes/js/jquery/jquery.js',cache:true,processData:false});
   
    console.log(typeof jQuery('iframe').dialog);
    window.setTimeout(function(){
        //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);
    },3000)
    //jQuery.ajax({url:jqurl,cache:true,processData:false});
});
</script>
</body></html>
Attachments (0)
Change History (6)

Changed November 10, 2013 12:52AM UTC by m_gol comment:1

owner: → anonymous
status: newpending

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

Changed November 16, 2013 02:13AM UTC by anonymous comment:2

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.

Changed November 16, 2013 02:33AM UTC by dmethvin comment:3

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.

Changed November 16, 2013 02:00PM UTC by scottgonzalez comment:4

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.

Changed November 16, 2013 02:20PM UTC by dmethvin comment:5

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.

Changed December 19, 2013 11:37PM UTC by anonymous comment:6

Yeah that explains a lot