1. #1
    Sencha User Greffin's Avatar
    Join Date
    Sep 2009
    Location
    Haugesund, Norway
    Posts
    25
    Vote Rating
    0
    Greffin is on a distinguished road

      0  

    Default Unanswered: How to make Element.load run scripts?

    Unanswered: How to make Element.load run scripts?


    Hi.

    I'm managing a page which updates it's content through xhr calls. This is done via the Element.load method. The response from such calls are in html, but at least one of my pages contain javascript which needs to be executed.

    My Ext Core version is 3.1.0. I've tried adding a callback function on my load:
    Code:
        element.load({
            url : 'index.php',
            method : 'GET',
            params : 'xhr=true&' + args,
            callback: function(options, success, response)    {
                var scriptsFinder = /<script[^>]*>([\s\S]+)<\/script>/gi;
                var scripts = scriptsFinder.exec(response.responseText);
                Ext.each(scripts, function(item, index, all) {
                    eval(item);
                });
            }
    This is part of the response I'm getting:
    Code:
                  <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
                  <script type="text/javascript">
                      alert("Hi world!");
    //                  Ext.onReady(function(){
                          var myLatlng = new google.maps.LatLng(59.427615, 5.381165);
                          var myOptions = {
                            zoom: 14,
                            center: myLatlng,
                            mapTypeId: google.maps.MapTypeId.ROADMAP
                          };
                          var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    //                  });
                  </script>
    I allways get an error message. In this case the message is:
    Code:
    missing ; before statement
                  <script type="text/javascript">
    which is probably because of the first script which fetches the google maps api.
    I've tried to move the first script into my main html header and just retain the second script, but then I receive the following error:
    Code:
    syntax error
                          var myLatlng = new google.maps.LatLng(59.427615, 5.381165);
    I would really like to have the possibility to execute scripts found in the response of such an ajax load. Anybody have any tips?

  2. #2
    Sencha User fay's Avatar
    Join Date
    Apr 2007
    Location
    Ireland
    Posts
    1,750
    Vote Rating
    9
    fay will become famous soon enough fay will become famous soon enough

      0  

    Default


    I just took a quick look at this, but would the problem be because you've commented out the wrong line:

    Code:
     
    <script type="text/javascript">
      alert("Hi world!");
    //  Ext.onReady(function(){
    I assume you want to comment out the alert, and not the onReady?

    Also, do you not need to specify loadScripts: true in the load call? In that case the onReady should fire, without the need to do the eval stuff.

  3. #3
    Sencha User Greffin's Avatar
    Join Date
    Sep 2009
    Location
    Haugesund, Norway
    Posts
    25
    Vote Rating
    0
    Greffin is on a distinguished road

      0  

    Default


    There is no "loadScripts" param which can be given to Element.load. There is in Ext.Updater, but this class is not included in Ext Core (at least not in 3.1.0).

    The Ext.onReady is commented out because it will never be fired. For Ajax calls there is no onReadyState event firing from Ext. There is however a callback provided from the Element.load method.

    I've tried many variations here...

  4. #4
    Sencha User Greffin's Avatar
    Join Date
    Sep 2009
    Location
    Haugesund, Norway
    Posts
    25
    Vote Rating
    0
    Greffin is on a distinguished road

      0  

    Default


    This works in jQuery:
    Code:
        $(el).load('?xhr=true&' + args);
    With response:
    Code:
                  <div id="map_canvas" style="width: 100%; height: 350px">&nbsp;</div>
    
                  <script type="text/javascript">
                      function pageInit()    {
                        var myLatlng = new google.maps.LatLng(59.427615, 5.381165);
                        var myOptions = {
                          zoom: 14,
                          center: myLatlng,
                          mapTypeId: google.maps.MapTypeId.ROADMAP
                        };
                        var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
                      }
                      $(function()    {
    //                Ext.onReady(function(){
                        pageInit();
                    });
                  </script>
    I would really like for this to be either a clean jQuery site or a clean Ext site. If anybody has any idea on how to do this in Ext Core, I would much appreciate it.

Similar Threads

  1. Scripts Don't Load and Stop
    By SIDGEY in forum Ext 2.x: Help & Discussion
    Replies: 2
    Last Post: 16 Feb 2010, 7:57 AM
  2. load scripts problem
    By tzander in forum Ext 2.x: Help & Discussion
    Replies: 6
    Last Post: 9 May 2008, 6:38 AM
  3. How to make autoLoad tabs reload and evaluate scripts in response
    By Morris in forum Ext 2.x: Help & Discussion
    Replies: 13
    Last Post: 1 Nov 2007, 3:20 PM
  4. [OPEN] Ext.Element.update(): better evaluation of Scripts
    By schmidetzki in forum Ext 1.x: Bugs
    Replies: 5
    Last Post: 3 Jun 2007, 5:27 AM
  5. Tabpanel and Load Scripts
    By JC in forum Ext 1.x: Help & Discussion
    Replies: 16
    Last Post: 14 Jan 2007, 12:05 AM

Thread Participants: 1

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi