views:

265

answers:

1

Hi All;

 $.get("CallBack.aspx", { nm: StateTx, nm2: StateTx2 }, function(data) {
                    $.each(data, function() {
                        $('[id$=DropDown1]').append("<option value=" + this['I3D'] + ">" + this['prmv'] + "</option>");
                    });
                });

İe 8 alt text

Mozilla Firefox alt text

my problem ie8 last item undefined. how do fix ?

Amain cm2 = new Amain();
                DataTable dt = cm2.Getdt(str, str3);
                StringBuilder sb = new StringBuilder();
                sb.Append("[");
                foreach (DataRow item in dt.Rows)
                {
                    sb.Append("{");
                    sb.Append("\"prmv\":\"");
                    sb.Append(item[0].ToString());
                    sb.Append("\"" + "},");
                }

                sb.Append("]");

                Context.Response.ContentType = "application/json";
                Context.Response.ContentEncoding = Encoding.UTF8;
                Context.Response.Write(sb.ToString());
                Context.Response.End();
+1  A: 

This can happen because of the way IE handles Javascript arrays. In IE,

var a = [1, 2, 3, 4,];

has five elements, the last of which is undefined. In Firefox, the last comma is ignored so the list has four elements.

Have a look at the exact data your Callback.aspx is returning.

Update: Your callback code causes this problem on the line:

                sb.Append("\"" + "},");

This will produce an array like:

[{"prmv":"1"},{"prmv":"2"},{"prmv":"3"},{"prmv":"4"},]
                                                    ^ extra comma

There is an extra comma before the ] of the returned array. One way to fix this might be to:

sb.Remove(sb.Length-1, 1); // remove extra trailing comma
sb.Append("]");

This fix will work for both IE and Firefox (and all other browsers).

Greg Hewgill
Data Dinamic Greg
Oraclee
@oraclee: Yes, but perhaps your `Callback.aspx` is formatting data in such as way as to include a trailing comma in the array. Perhaps you could post the code for `Callback.aspx` if it's not too long.
Greg Hewgill
ok add callback.aspx code
Oraclee
Greg very very very thank you Work
Oraclee