null or not an object in IE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • macaco
    New Member
    • Apr 2007
    • 9

    null or not an object in IE

    I have developed a webapp that works very good on firefox and opera, but on IE I keep getting an error message.

    I use AJAX to communicate with a PHP file that queries a MySQL database and returns the information in JSON.
    Code:
    function sendQuerystring2(url,mod,columna)
    {
    	http2.open("GET", url, true);
    	if (mod == "tabla") {
    		http2.onreadystatechange = function (){
    			if (http2.readyState == 4) {
    				hide('cargando');
    				if (http2.status == 200) {
    					obj_detalle = eval('(' + http2.responseText + ')');
    					crear_tabla(columna);
    				}
    			} else {
    				show('cargando');
    			}
    		}	
    	}
    Code:
    {"items":[{"id":"1","titulo":"Prueba"}]}
    obj_detalle['items'][0].id, is "null or not an object" in IE, while in firefox works perfectly.

    I have tried an alert(http2.res ponseText) and it has the correct content.

    does anyone know a fix to this?
    many thanks.
  • iam_clint
    Recognized Expert Top Contributor
    • Jul 2006
    • 1207

    #2
    why are you using eval?

    Comment

    • macaco
      New Member
      • Apr 2007
      • 9

      #3
      Originally posted by iam_clint
      why are you using eval?
      because it's the way to use JSON. it turns the sent string into a javascript object.

      I have also tried with POST instead of GET.. but still getting the same results.

      Comment

      • iam_clint
        Recognized Expert Top Contributor
        • Jul 2006
        • 1207

        #4
        i guess i don't understand why a string needs to be an object?

        Comment

        • macaco
          New Member
          • Apr 2007
          • 9

          #5
          because it's not only this:

          {"items":[{"id":"1","titu lo":"Prueba"}]}

          there are many items with many other "properties ". and I think this is the best way to parse this information. something similar to XML in a way. I can access any property like this:

          obj_detalle.ite ms[itemNumber].property

          though I it is not working on IE.

          Comment

          Working...