Results 1 to 8 of 8

Thread: javascript array problems

  1. #1
    Join Date
    May 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default javascript array problems

    i have the array
    Code:
    	SPECIAL_DAYS = {
    
    	};
    i want to put the value of "results" into SPECIAL_DAYS, results contains the following (results is a variable from the result of an AJAX call):

    Code:
            "2006-5" : [ 5 ],
    	"2006-6" : [ 3 ],
    	"2006-7" : [ 7 ],
    	"2006-8" : [ 4 ],
    	"2006-9" : [ 2 ],
    	"2006-10" : [ 6 ],
    	"2006-11" : [ 4 ],
    	"2007-0" : [ 1 ],
    	"2007-1" : [ 5 ],
    	"2007-2" : [ 5 ],
    	"2007-3" : [ 2 ],
    	"2007-4" : [ 7 ],
    	"2007-5" : [ 4 ],
    	"2007-6" : [ 2 ],
    	"2007-7" : [ 6 ],
    	"2007-8" : [ 3 ],
    	"2007-9" : [ 1 ],
    	"2007-10" : [ 5 ]
    i'm stumped, any suggestions?

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    One of the rare instances where the eval() call is appropriate, methinks.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    May 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    i'm relatively new to javascript so no doubt people across the world will slap their foreheads when they see what i tried!

    Code:
    	SPECIAL_DAYS = {
    		eval(results);
    	};
    This (probably not surprisingly) didnt work...

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I think:
    Code:
    		eval("SPECIAL_DAYS = { " + results + " };");
    would work better.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    May 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    thanks, that worked

  6. #6
    Join Date
    May 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    oops, that works in FireFox but not in Internet Explorer, it causes an "Undefined Error"

  7. #7
    Join Date
    May 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    ah, i think ive pinpointed the problem..

    I'm using an http.open request to send all the fields in a form to a PHP file, it works perfectly in Firefox, but in IE it gives an error - is there a maximum string length that can be used in an http.open call?

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Not insofar as I know.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •