Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

jquery object and string comparison..

  • 09-03-2010 06:40PM
    #1
    Registered Users, Registered Users 2 Posts: 1,127 ✭✭✭


    My god? I think Im going mad? What the hell is wrong with this code?
            log(typeof t); 
            // This is fine, returns 'string', 
            // like a good ickle jquery function
            $.getJSON("/js/json/jsonsource.js",function(js){
                $.each(js.items, function(i, n){
                    if( n.id == b_idx ){
                        $.each(n.pricing, function(y, h){
                            log(typeof t);  
                            // This goes mad?!? Returns 'object'.. 
                            // but I didnt change it? 
                            log(h.id == t); 
                            // This fails, I need to compare the value of t, 
                            // to a parameter here, but it wont let me cos 
                            // they are different datatypes..
                        });
                    }
                });
            });
    

    I've commented the code to show you whats going on.. Firebug spits out "string" for the first typeof, and "object" for the second, but I never cast it?

    Any ideas? By the way, there's nothing wrong with any of the json retrieval, the only thing that fails is the comparison.


Comments

  • Closed Accounts Posts: 2,696 ✭✭✭mark renton


    Dunno - but you should post this in best source code comment

    // This is fine, returns 'string',
    // like a good ickle jquery function


  • Registered Users, Registered Users 2 Posts: 1,127 ✭✭✭smcelhinney


    Oh I have had better..

    Like the
    // Go to bed Stephen, and do this fcuking XMLHttpRequest implementation in the morning
    

    that ended up on a production webserver..


Advertisement