Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Ajax Script Breaking Javascript: Can I Have Help?

    Hi,

    I'm pretty new to this whole thing, and specifically, Javascript.

    I recently downloaded and installed this script for my website. I got it to work perfectly, however, it completely breaks all my Javascript, including Jquery scripts. This was a documented bug, but there was a fix provided with it.

    "Javascript included in pages that are loaded using AJAX will be discarded. Use the addEventListener-function on the load_complete event to execute javascript onload."

    Sadly, I'm completely unfamiliar with the terms and the know-how, so I was hoping that anyone could help me restore function to the javascript on the webpages.

    Thanks for the time.

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Running an entire site through a custom JS class seems an astonishingly bad idea, especially so if you're new to JS. But hey, it's your site..

    The event handler they're referring to is documented here, and I'd guess that to use it, you'd replace anything that looks like:

    Code:
    $(document).ready(function(){
    // do stuff
    });
    with:

    Code:
    bda.addEventListener('load_complete', function(){
    //do stuff
    });
    although how that lot is going to play with jQuery is anyone's guess...

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Spudhead View Post
    Running an entire site through a custom JS class seems an astonishingly bad idea, especially so if you're new to JS. But hey, it's your site..

    The event handler they're referring to is documented here, and I'd guess that to use it, you'd replace anything that looks like:

    Code:
    $(document).ready(function(){
    // do stuff
    });
    with:

    Code:
    bda.addEventListener('load_complete', function(){
    //do stuff
    });
    although how that lot is going to play with jQuery is anyone's guess...
    Hi,

    Thanks for the reply. I tried it and it didn't work. Could you give me an example please.

    I did find others with the same problem and the solution was to include this code.


    Code:
    var req;
    function callPage(pageUrl, divElementId, loadinglMessage, pageErrorMessage) {
         document.getElementById(divElementId).innerHTML = loadinglMessage;
         try {
         req = new XMLHttpRequest(); /* e.g. Firefox */
         } catch(e) {
           try {
           req = new ActiveXObject("Msxml2.XMLHTTP");  /* some versions IE */
           } catch (e) {
             try {
             req = new ActiveXObject("Microsoft.XMLHTTP");  /* some versions IE */
             } catch (E) {
              req = false;
             } 
           } 
         }
         req.onreadystatechange = function() {responsefromServer(divElementId, pageErrorMessage);};
         req.open("GET",pageUrl,true);
         req.send(null);
      }
     
    function responsefromServer(divElementId, pageErrorMessage) {
       var output = '';
       if(req.readyState == 4) {
          if(req.status == 200) {
             output = req.responseText;
             document.getElementById(divElementId).innerHTML = parseScript(output);
             } else {
             document.getElementById(divElementId).innerHTML = pageErrorMessage+"\n"+output;
             }
          }
      }
     
    function parseScript(_source) {
    		var source = _source;
    		var scripts = new Array();
     
    		// Strip out tags
    		while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
    			var s = source.indexOf("<script");
    			var s_e = source.indexOf(">", s);
    			var e = source.indexOf("</script", s);
    			var e_e = source.indexOf(">", e);
     
    			// Add to scripts array
    			scripts.push(source.substring(s_e+1, e));
    			// Strip from source
    			source = source.substring(0, s) + source.substring(e_e+1);
    		}
     
    		// Loop through every script collected and eval it
    		for(var i=0; i<scripts.length; i++) {
    			try {
    				eval(scripts[i]);
    			}
    			catch(ex) {
    				// do what you want here when a script fails
    			}
    		}
    		// Return the cleaned source
    		return source;}
    Sadly I don't know how to implement the code. If you would like to see my website so far, please visit http:://www.baxy-z.com/5 where the source codes are.

    Also, I know it's possible to get Jquery and other Java working as the author's demo site uses it. http://www.bydust.com/examples/fhi-zin/

    Also, I think the magic happens in main.js.

    All help is appreciated!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •