You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Alexei Sokolov <al...@gmail.com> on 2007/10/19 03:56:50 UTC

ajax with external javascripts

Hey guys,

Very good progress on 1.3 release, congratulations.
However, there is an  issue which somebody complained around july 31,
07 that has not been
addressed yet.

Short description: I cannot reference any external javascript files (from
yahoo, google, even from subdomain) in markup of a panel if I want that
panel to be updated using ajax. All browsers complain.

Long Description: I believe the problem lies inside wicket-ajax.js, more
precisely in Wicket.Head.Contributor.ProcessScript method. Existing
implementation attempts to load the referenced script using ajax, and
browsers do not allow that due to security concerns. See any article on
cross-domain ajax for the explanation why.

Steps to reproduce:

1. create a panel.
2. include something like <wicket:head><script type="text/javascript" src="
http://blah.blah.com/script.js"></script></wicket:head>
3. attempt to update the panel using ajax
4. each and every browser will complain, but the error will be
slightly different. firefox will say "uncaught exception: Permission
denied to call method XMLHttpRequest.open"


Alex

Re: ajax with external javascripts

Posted by Martijn Dashorst <ma...@gmail.com>.
On 10/19/07, Matej Knopp <ma...@gmail.com> wrote:
> Actually, this might be a good idea, given all browsers support
> script.readState consistently, which I need to confirm first. Apart
> from that, I don't see any problem with it so far.

This link may be of interest for cross browser xmlhttprequest,
especially with respect to ready state bugs:

http://feeds.feedburner.com/~r/ajaxian/~3/171125419/re-inventing-xmlhttprequest-cross-browser-implementation-with-sniffing-capabilities

Martijn



-- 
Buy Wicket in Action: http://manning.com/dashorst
Apache Wicket 1.3.0-beta4 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.0-beta4/

Re: ajax with external javascripts

Posted by Alexei Sokolov <al...@gmail.com>.
I think the script should be updated a bit... I don't think 'this' is set
correctly in onload handler.

Alex

On 10/19/07, Matej Knopp <ma...@gmail.com> wrote:
>
> Actually, this might be a good idea, given all browsers support
> script.readState consistently, which I need to confirm first. Apart
> from that, I don't see any problem with it so far.
>
> -Matej
>
> On 10/19/07, Alexei Sokolov <al...@gmail.com> wrote:
> > Actually,
> >
> > The following code seems to be working in ie and firefox for me, but it
> was
> > a very simple test.
> >
> > Alex
> >
> >     processScript: function(steps, node) {
> >         steps.push(function(notify) {
> >             if (Wicket.DOM.containsElement(node) ||
> >                 Wicket.Head.containsElement(node, "src")) {
> >                 notify();
> >                 return;
> >             }
> >             var src = node.getAttribute("src");
> >             if (src != null && src != "") {
> >
> >                 var script = Wicket.Head.createElement("script");
> >                 script.src = src;
> >                 var done = false;
> >
> >                 // Attach handlers for all browsers
> >                 script.onload = script.onreadystatechange = function(){
> >                     if ( !done && (!this.readyState ||
> >                             this.readyState == "loaded" ||
> > this.readyState== "complete") ) {
> >                         done = true;
> >
> >                         var head = document.getElementsByTagName
> ("head");
> >
> >                         if (head[0]) {
> >                             // how about Wicket.Head.removeElement() ???
> >                             head[0].removeChild(script);
> >                         }
> >                         // maybe I need to do something here?
> >                         notify();
> >                     }
> >                 };
> >                 Wicket.Head.addElement(script);
> >
> >
> >                 //var onLoad = function() {
> >                 //    Wicket.Head.addJavascript(content, null, src);
> >                 //    Wicket.Ajax.invokePostCallHandlers();
> >                 //    notify();
> >                 //}
> >
> >                 // we need to schedule the request as timeout
> >                 // calling xml http request from another request call
> stack
> > doesn't work
> >                 //window.setTimeout(function() {
> >                 //    var req = new Wicket.Ajax.Request(src, onLoad,
> false,
> > false);
> >                 //    req.debugContent = false;
> >                 //    if (Wicket.Browser.isKHTML())
> >                 //        req.async = false;
> >                 //    req.get();
> >                 // },1);
> >             } else {
> >                 var text = Wicket.DOM.serializeNodeChildren(node);
> >                 Wicket.Head.addJavascript(text, node.getAttribute
> ("id"));
> >                 notify();
> >             }
> >         });
> >     }
> >
> > On 10/18/07, Igor Vaynberg <ig...@gmail.com> wrote:
> > >
> > > matej what do you think about this?
> > >
> > > -igor
> > >
> > >
> > > On 10/18/07, Alexei Sokolov <al...@gmail.com> wrote:
> > > > Maybe something similar to this:
> > > > http://docs.jquery.com/Ajax/jQuery.getScript. They use <script> tag
> > > > injection (see 1.2.1 jquery source code).
> > > >
> > > > Alex
> > > >
> > > > On 10/18/07, Igor Vaynberg <ig...@gmail.com> wrote:
> > > > >
> > > > > do you have any suggestions on how to fix it?
> > > > >
> > > > > -igor
> > > > >
> > > > >
> > > > > On 10/18/07, Alexei Sokolov <al...@gmail.com> wrote:
> > > > > > Hey guys,
> > > > > >
> > > > > > Very good progress on 1.3 release, congratulations.
> > > > > > However, there is an  issue which somebody complained around
> july
> > > 31,
> > > > > > 07 that has not been
> > > > > > addressed yet.
> > > > > >
> > > > > > Short description: I cannot reference any external javascript
> files
> > > > > (from
> > > > > > yahoo, google, even from subdomain) in markup of a panel if I
> want
> > > that
> > > > > > panel to be updated using ajax. All browsers complain.
> > > > > >
> > > > > > Long Description: I believe the problem lies inside
> wicket-ajax.js,
> > > more
> > > > > > precisely in Wicket.Head.Contributor.ProcessScript method.
> Existing
> > > > > > implementation attempts to load the referenced script using
> ajax,
> > > and
> > > > > > browsers do not allow that due to security concerns. See any
> article
> > > on
> > > > > > cross-domain ajax for the explanation why.
> > > > > >
> > > > > > Steps to reproduce:
> > > > > >
> > > > > > 1. create a panel.
> > > > > > 2. include something like <wicket:head><script
> > > type="text/javascript"
> > > > > src="
> > > > > > http://blah.blah.com/script.js"></script></wicket:head>
> > > > > > 3. attempt to update the panel using ajax
> > > > > > 4. each and every browser will complain, but the error will be
> > > > > > slightly different. firefox will say "uncaught exception:
> Permission
> > > > > > denied to call method XMLHttpRequest.open"
> > > > > >
> > > > > >
> > > > > > Alex
> > > > > >
> > > > >
> > > >
> > >
> >
>

Re: ajax with external javascripts

Posted by Matej Knopp <ma...@gmail.com>.
Actually, this might be a good idea, given all browsers support
script.readState consistently, which I need to confirm first. Apart
from that, I don't see any problem with it so far.

-Matej

On 10/19/07, Alexei Sokolov <al...@gmail.com> wrote:
> Actually,
>
> The following code seems to be working in ie and firefox for me, but it was
> a very simple test.
>
> Alex
>
>     processScript: function(steps, node) {
>         steps.push(function(notify) {
>             if (Wicket.DOM.containsElement(node) ||
>                 Wicket.Head.containsElement(node, "src")) {
>                 notify();
>                 return;
>             }
>             var src = node.getAttribute("src");
>             if (src != null && src != "") {
>
>                 var script = Wicket.Head.createElement("script");
>                 script.src = src;
>                 var done = false;
>
>                 // Attach handlers for all browsers
>                 script.onload = script.onreadystatechange = function(){
>                     if ( !done && (!this.readyState ||
>                             this.readyState == "loaded" ||
> this.readyState== "complete") ) {
>                         done = true;
>
>                         var head = document.getElementsByTagName("head");
>
>                         if (head[0]) {
>                             // how about Wicket.Head.removeElement() ???
>                             head[0].removeChild(script);
>                         }
>                         // maybe I need to do something here?
>                         notify();
>                     }
>                 };
>                 Wicket.Head.addElement(script);
>
>
>                 //var onLoad = function() {
>                 //    Wicket.Head.addJavascript(content, null, src);
>                 //    Wicket.Ajax.invokePostCallHandlers();
>                 //    notify();
>                 //}
>
>                 // we need to schedule the request as timeout
>                 // calling xml http request from another request call stack
> doesn't work
>                 //window.setTimeout(function() {
>                 //    var req = new Wicket.Ajax.Request(src, onLoad, false,
> false);
>                 //    req.debugContent = false;
>                 //    if (Wicket.Browser.isKHTML())
>                 //        req.async = false;
>                 //    req.get();
>                 // },1);
>             } else {
>                 var text = Wicket.DOM.serializeNodeChildren(node);
>                 Wicket.Head.addJavascript(text, node.getAttribute("id"));
>                 notify();
>             }
>         });
>     }
>
> On 10/18/07, Igor Vaynberg <ig...@gmail.com> wrote:
> >
> > matej what do you think about this?
> >
> > -igor
> >
> >
> > On 10/18/07, Alexei Sokolov <al...@gmail.com> wrote:
> > > Maybe something similar to this:
> > > http://docs.jquery.com/Ajax/jQuery.getScript. They use <script> tag
> > > injection (see 1.2.1 jquery source code).
> > >
> > > Alex
> > >
> > > On 10/18/07, Igor Vaynberg <ig...@gmail.com> wrote:
> > > >
> > > > do you have any suggestions on how to fix it?
> > > >
> > > > -igor
> > > >
> > > >
> > > > On 10/18/07, Alexei Sokolov <al...@gmail.com> wrote:
> > > > > Hey guys,
> > > > >
> > > > > Very good progress on 1.3 release, congratulations.
> > > > > However, there is an  issue which somebody complained around july
> > 31,
> > > > > 07 that has not been
> > > > > addressed yet.
> > > > >
> > > > > Short description: I cannot reference any external javascript files
> > > > (from
> > > > > yahoo, google, even from subdomain) in markup of a panel if I want
> > that
> > > > > panel to be updated using ajax. All browsers complain.
> > > > >
> > > > > Long Description: I believe the problem lies inside wicket-ajax.js,
> > more
> > > > > precisely in Wicket.Head.Contributor.ProcessScript method. Existing
> > > > > implementation attempts to load the referenced script using ajax,
> > and
> > > > > browsers do not allow that due to security concerns. See any article
> > on
> > > > > cross-domain ajax for the explanation why.
> > > > >
> > > > > Steps to reproduce:
> > > > >
> > > > > 1. create a panel.
> > > > > 2. include something like <wicket:head><script
> > type="text/javascript"
> > > > src="
> > > > > http://blah.blah.com/script.js"></script></wicket:head>
> > > > > 3. attempt to update the panel using ajax
> > > > > 4. each and every browser will complain, but the error will be
> > > > > slightly different. firefox will say "uncaught exception: Permission
> > > > > denied to call method XMLHttpRequest.open"
> > > > >
> > > > >
> > > > > Alex
> > > > >
> > > >
> > >
> >
>

Re: ajax with external javascripts

Posted by Alexei Sokolov <al...@gmail.com>.
Actually,

The following code seems to be working in ie and firefox for me, but it was
a very simple test.

Alex

    processScript: function(steps, node) {
        steps.push(function(notify) {
            if (Wicket.DOM.containsElement(node) ||
                Wicket.Head.containsElement(node, "src")) {
                notify();
                return;
            }
            var src = node.getAttribute("src");
            if (src != null && src != "") {

                var script = Wicket.Head.createElement("script");
                script.src = src;
                var done = false;

                // Attach handlers for all browsers
                script.onload = script.onreadystatechange = function(){
                    if ( !done && (!this.readyState ||
                            this.readyState == "loaded" ||
this.readyState== "complete") ) {
                        done = true;

                        var head = document.getElementsByTagName("head");

                        if (head[0]) {
                            // how about Wicket.Head.removeElement() ???
                            head[0].removeChild(script);
                        }
                        // maybe I need to do something here?
                        notify();
                    }
                };
                Wicket.Head.addElement(script);


                //var onLoad = function() {
                //    Wicket.Head.addJavascript(content, null, src);
                //    Wicket.Ajax.invokePostCallHandlers();
                //    notify();
                //}

                // we need to schedule the request as timeout
                // calling xml http request from another request call stack
doesn't work
                //window.setTimeout(function() {
                //    var req = new Wicket.Ajax.Request(src, onLoad, false,
false);
                //    req.debugContent = false;
                //    if (Wicket.Browser.isKHTML())
                //        req.async = false;
                //    req.get();
                // },1);
            } else {
                var text = Wicket.DOM.serializeNodeChildren(node);
                Wicket.Head.addJavascript(text, node.getAttribute("id"));
                notify();
            }
        });
    }

On 10/18/07, Igor Vaynberg <ig...@gmail.com> wrote:
>
> matej what do you think about this?
>
> -igor
>
>
> On 10/18/07, Alexei Sokolov <al...@gmail.com> wrote:
> > Maybe something similar to this:
> > http://docs.jquery.com/Ajax/jQuery.getScript. They use <script> tag
> > injection (see 1.2.1 jquery source code).
> >
> > Alex
> >
> > On 10/18/07, Igor Vaynberg <ig...@gmail.com> wrote:
> > >
> > > do you have any suggestions on how to fix it?
> > >
> > > -igor
> > >
> > >
> > > On 10/18/07, Alexei Sokolov <al...@gmail.com> wrote:
> > > > Hey guys,
> > > >
> > > > Very good progress on 1.3 release, congratulations.
> > > > However, there is an  issue which somebody complained around july
> 31,
> > > > 07 that has not been
> > > > addressed yet.
> > > >
> > > > Short description: I cannot reference any external javascript files
> > > (from
> > > > yahoo, google, even from subdomain) in markup of a panel if I want
> that
> > > > panel to be updated using ajax. All browsers complain.
> > > >
> > > > Long Description: I believe the problem lies inside wicket-ajax.js,
> more
> > > > precisely in Wicket.Head.Contributor.ProcessScript method. Existing
> > > > implementation attempts to load the referenced script using ajax,
> and
> > > > browsers do not allow that due to security concerns. See any article
> on
> > > > cross-domain ajax for the explanation why.
> > > >
> > > > Steps to reproduce:
> > > >
> > > > 1. create a panel.
> > > > 2. include something like <wicket:head><script
> type="text/javascript"
> > > src="
> > > > http://blah.blah.com/script.js"></script></wicket:head>
> > > > 3. attempt to update the panel using ajax
> > > > 4. each and every browser will complain, but the error will be
> > > > slightly different. firefox will say "uncaught exception: Permission
> > > > denied to call method XMLHttpRequest.open"
> > > >
> > > >
> > > > Alex
> > > >
> > >
> >
>

Re: ajax with external javascripts

Posted by Igor Vaynberg <ig...@gmail.com>.
matej what do you think about this?

-igor


On 10/18/07, Alexei Sokolov <al...@gmail.com> wrote:
> Maybe something similar to this:
> http://docs.jquery.com/Ajax/jQuery.getScript. They use <script> tag
> injection (see 1.2.1 jquery source code).
>
> Alex
>
> On 10/18/07, Igor Vaynberg <ig...@gmail.com> wrote:
> >
> > do you have any suggestions on how to fix it?
> >
> > -igor
> >
> >
> > On 10/18/07, Alexei Sokolov <al...@gmail.com> wrote:
> > > Hey guys,
> > >
> > > Very good progress on 1.3 release, congratulations.
> > > However, there is an  issue which somebody complained around july 31,
> > > 07 that has not been
> > > addressed yet.
> > >
> > > Short description: I cannot reference any external javascript files
> > (from
> > > yahoo, google, even from subdomain) in markup of a panel if I want that
> > > panel to be updated using ajax. All browsers complain.
> > >
> > > Long Description: I believe the problem lies inside wicket-ajax.js, more
> > > precisely in Wicket.Head.Contributor.ProcessScript method. Existing
> > > implementation attempts to load the referenced script using ajax, and
> > > browsers do not allow that due to security concerns. See any article on
> > > cross-domain ajax for the explanation why.
> > >
> > > Steps to reproduce:
> > >
> > > 1. create a panel.
> > > 2. include something like <wicket:head><script type="text/javascript"
> > src="
> > > http://blah.blah.com/script.js"></script></wicket:head>
> > > 3. attempt to update the panel using ajax
> > > 4. each and every browser will complain, but the error will be
> > > slightly different. firefox will say "uncaught exception: Permission
> > > denied to call method XMLHttpRequest.open"
> > >
> > >
> > > Alex
> > >
> >
>

Re: ajax with external javascripts

Posted by Alexei Sokolov <al...@gmail.com>.
Maybe something similar to this:
http://docs.jquery.com/Ajax/jQuery.getScript. They use <script> tag
injection (see 1.2.1 jquery source code).

Alex

On 10/18/07, Igor Vaynberg <ig...@gmail.com> wrote:
>
> do you have any suggestions on how to fix it?
>
> -igor
>
>
> On 10/18/07, Alexei Sokolov <al...@gmail.com> wrote:
> > Hey guys,
> >
> > Very good progress on 1.3 release, congratulations.
> > However, there is an  issue which somebody complained around july 31,
> > 07 that has not been
> > addressed yet.
> >
> > Short description: I cannot reference any external javascript files
> (from
> > yahoo, google, even from subdomain) in markup of a panel if I want that
> > panel to be updated using ajax. All browsers complain.
> >
> > Long Description: I believe the problem lies inside wicket-ajax.js, more
> > precisely in Wicket.Head.Contributor.ProcessScript method. Existing
> > implementation attempts to load the referenced script using ajax, and
> > browsers do not allow that due to security concerns. See any article on
> > cross-domain ajax for the explanation why.
> >
> > Steps to reproduce:
> >
> > 1. create a panel.
> > 2. include something like <wicket:head><script type="text/javascript"
> src="
> > http://blah.blah.com/script.js"></script></wicket:head>
> > 3. attempt to update the panel using ajax
> > 4. each and every browser will complain, but the error will be
> > slightly different. firefox will say "uncaught exception: Permission
> > denied to call method XMLHttpRequest.open"
> >
> >
> > Alex
> >
>

Re: ajax with external javascripts

Posted by Igor Vaynberg <ig...@gmail.com>.
do you have any suggestions on how to fix it?

-igor


On 10/18/07, Alexei Sokolov <al...@gmail.com> wrote:
> Hey guys,
>
> Very good progress on 1.3 release, congratulations.
> However, there is an  issue which somebody complained around july 31,
> 07 that has not been
> addressed yet.
>
> Short description: I cannot reference any external javascript files (from
> yahoo, google, even from subdomain) in markup of a panel if I want that
> panel to be updated using ajax. All browsers complain.
>
> Long Description: I believe the problem lies inside wicket-ajax.js, more
> precisely in Wicket.Head.Contributor.ProcessScript method. Existing
> implementation attempts to load the referenced script using ajax, and
> browsers do not allow that due to security concerns. See any article on
> cross-domain ajax for the explanation why.
>
> Steps to reproduce:
>
> 1. create a panel.
> 2. include something like <wicket:head><script type="text/javascript" src="
> http://blah.blah.com/script.js"></script></wicket:head>
> 3. attempt to update the panel using ajax
> 4. each and every browser will complain, but the error will be
> slightly different. firefox will say "uncaught exception: Permission
> denied to call method XMLHttpRequest.open"
>
>
> Alex
>