SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    May 2010
    Location
    Exeter, Devon. UK.
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript not being fired in Firefox unless alert() boxes used (Solved)

    Hi guys,

    I've stumbled into an issue in the past day where I have developed a small process in JavaScript that takes in information that the user has entered, and uses a combination of JavaScript and jQuery to return results. Workflow such as:

    1) User enters location details
    2) Javascript onClick function to submit to an internal js function
    3) Use GDownloadUrl to download an XML file on the fly for data processing
    4) Process data
    5) Use jQuery to output results into a div

    I am using variable functions such as:

    Code JavaScript:
    var search = {
       performSearch: function() {
          ...
          ...
       }
    }

    It all worked in Firefox when I was debugging with Firebug, however as soon as I stop using firebug it doesn't do anything. I've tested it by putting alert() statements in different parts of the code - if the alerts are near the start of the process everything works as expected though if added at the end nothing happens.

    I've looked at this in IE 8 and it's working perfectly! (which is a nice surprise!)

    Can anyone suggest what's the problem??

    Many thanks

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    A timing issue with respect to the XML data call? Maybe IE8 runs slower or reacts differently to the XML return and so seems to work OK?

    Without more detail/code then I guess we can only speculate.

    What about Opera or Safari or Chrome - how do they respond?
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Member
    Join Date
    May 2010
    Location
    Exeter, Devon. UK.
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Of course!
    Thanks siteguru - I didn't appreciate the difference in speed, and plus I've had my head stuck in it for the past 24hrs and couldn't see the obvious.

    Instead of using:

    Code JavaScript:
    GDownloadUrl(location, function (data, responseCode) {
    	var xml = GXml.parse(data);
    .....

    Which appeared to open the file though not necessarily fire the code off as expected. I've changed it to only execute after onload:

    Code JavaScript:
    	loadXMLSiteForecast: function() {
    		var location = "feeds/mylocations.xml";
    		if (window.ActiveXObject) {
    			search.xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    		}
    		// code for Mozilla, Firefox, Opera, etc.
    		else if (document.implementation && document.implementation.createDocument) {
    			search.xmlDoc=document.implementation.createDocument("","",null);
    		} else {
    			alert('Your browser cannot handle this script');
    		}
    		search.xmlDoc.async=false;
    		search.xmlDoc.load(location);		
    		search.xmlDoc.onload=search.matchAndOutputData();
    	},

    Thanks so much!!

  4. #4
    SitePoint Member
    Join Date
    May 2010
    Location
    Exeter, Devon. UK.
    Posts
    17
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    p.s. is there a way of closing this post, and marking it as solved?

  5. #5
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,629
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Edit the original post and change the title to SOLVED? (Maybe not - I think you only get a certain time window to be able to edit old posts. Maybe a mod will do it. )
    Ian Anderson
    www.siteguru.co.uk

  6. #6
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,784
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    I have changed the thread title to indicate that it contains the solution.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


Bookmarks

Posting Permissions

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