SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2011
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Trouble retrieving variable in seperate javascript file in all versions of IE

    Hello everyone,

    In my page I have a function that takes in a parameter and passes that value to the jquery's getScript function.
    Here is an example

    Code JavaScript:
    function getRoute(routeNumber){
       $.getScript('http://www.mySite.com/Scripts/Route' + routeNumber + '_trace.js',function(){
          var routeInfo = routeTrace // routeTrace is defined in the dynamically formed javascript.
       }
    }

    The javascript file being called would contain something as simple as this.

    Code JavaScript:
        var routeTrace = "96,bus,46.123456,96.123456";

    In Firefox and Chrome, routeInfo does return the correct values. In IE6+, routeInfo returns undefined.
    Obviously this is a cross browser issue and I went through numerous topics and found no solution.

    Firefox and Chrome executes as expected with the callback function being called after the script has loaded.
    IE6+ on the other hand behaves differently. Help is greatly appreciated.

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,183
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Does the file your requesting exist on the same domain your script is running on? If not then that's the reason why as cross domain requests are forbidden between 2 different domains.
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2011
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, it's on a different sub domain. This works fine in Chrome and FF though. In the meantime I'll keep looking around.

    I'm not getting any cross domain error either. Just says that routeTrace is undefined.

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2011
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Update: I used bare minimum code on IE and it does work. It appears something else is affecting it. When i find it I'll post it up. Thanks for your help.

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2011
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ahh IE needed the $.Trim() method on value I was passing. I'll have to keep this in mind when working with other peoples data.


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
  •