...

View Full Version : how to stop the eval sorting in IE9



chittivenureddy
07-06-2011, 04:30 PM
in IE9 Browser list of country names sorting on keys.
we are using Ajax
javascript:


var data= remoteRequest(url);

the data like


data={" 11":"Australia"," 14":"Bermuda"," CAN":"Canada"," 12":"France"," 15":"Germany"," IND":"India"," 16":"Russia"," 13":"South Africa"," 10":"UK"," USA":"United States"}
name_set= eval('('+data+')');

it fine in all browser
the array like


name_set[11]=Australia
name_set[14]=Bermuda
name_set[CAN]=Canada
name_set[12]=France
name_set[15]=Germany
name_set[IND]=India
name_set[16]=Russia
name_set[13]=South Africa
name_set[10]=UK
name_set[USA]=United States

but in the IE9 browser array keys sorting as like.


name_set[10]=UK
name_set[11]=Australia
name_set[12]=France
name_set[13]=South Africa
name_set[14]=Bermuda
name_set[15]=Germany
name_set[16]=Russia
name_set[CAN]=Canada
name_set[IND]=India
name_set[USA]=United States

so please help me, how to stop the array sorting in IE9.

thanks in Advance,
Venu

Kor
07-06-2011, 04:41 PM
What you have there is an Object (that means an unsorted, unordered list) not an Array (which is an ordered list).

See the difference:
http://json.org

As long as you are dealing with an object, it does not matter too much in which order the pairs property:value are arranged, because you can not circle through them using and indent. An Object has no length.

But if, for a reason or another, you need that pairs to be sorted upon the value, not upon the key (property) why don't you sort them using a sorting algorithm? Do you need such a code?

Kor
07-06-2011, 04:57 PM
By the way: I can not confirm that "sorting" you are talking about. In my IE9 there is no such a "sorting".

And your data should look as a string (see the blue quotes), like:


var data='{" 11":"Australia"," 14":"Bermuda"," CAN":"Canada"," 12":"France"," 15":"Germany"," IND":"India"," 16":"Russia"," 13":"South Africa"," 10":"UK"," USA":"United States"}';

otherwise what's the point of evaluating it? The way you have written it, there is straight a JSON object.

bhaskar9
10-27-2011, 02:52 PM
Hi Venu Did you find the solution? Please let me know

Thanks,
Bhaskar



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum