Loading ...
Sorry, an error occurred while loading the content.

368Re:[json] My javascript app freezes at eval'uating JSON string returned

Expand Messages
  • rancioadams
    May 27, 2006
      BTW: Here's the string returned by JSON, just in case:

      ["160","GENERAL DE
      OBRA","HORMIGONERAS","REF.","TIPO","CORRIENTE","P\/HORA","LITRO","","","","","EURO\/DIA","SEG.\/DIA",null,null,null,null]

      p

      --- In json@yahoogroups.com, "rancioadams" <comomolo@...> wrote:
      >
      > Here's the server code:
      > <meta http-equiv="content-type" content="text/html;charset=utf-8">
      > <?php
      >
      > require_once('JSON.php');
      > $json = new Services_JSON();
      >
      > $con=mysql_connect("xxxxx", "xxxxx", "xxxxx");
      >
      > if (!$con)
      > {
      > die('Could not connect: ' . mysql_error());
      > }
      > mysql_select_db("xxxxx", $con);
      >
      > $subfamilia = utf8_decode($_GET["subfamilia"]);
      >
      > $sql = "SELECT * FROM equipos WHERE SUBFAMILIA = '$subfamilia'";
      >
      > $query = mysql_query($sql) or die(mysql_error());
      >
      > $row = mysql_fetch_row($query);
      > echo $json->encode($row);
      >
      > ?>
      >
      > And here's the client code:
      >
      > function getLista(subfamilia)
      > {
      > var xmlhttp=false;
      >
      > try
      > {
      > xmlhttp = new ActiveXObject('Msxml2.XMLHTTP');
      > }
      >
      > catch (e)
      > {
      > try
      > {
      > xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
      > }
      > catch (E)
      > {
      > xmlhttp = false;
      > }
      > }
      >
      > if (!xmlhttp && typeof XMLHttpRequest!='undefined')
      > {
      > xmlhttp = new XMLHttpRequest();
      > }
      >
      > var url = 'scripts/getLista.php?subfamilia=' +
      > encodeURIComponent(subfamilia);
      >
      > xmlhttp.open('GET', url, true);
      >
      > xmlhttp.onreadystatechange=function()
      > {
      > switch (xmlhttp.readyState)
      > {
      > case 1:
      > document.getElementById('lista').innerHTML = "Loading...";
      > break;
      >
      > case 4:
      > document.write("before <br />");
      >
      > document.write(xmlhttp.responseText + "<br />");
      >
      > var tabla = eval(xmlhttp.responseText);
      > document.write(tabla[2] + "<br />");
      >
      > document.write("after <br />");
      >
      > break;
      > }
      > }
      > xmlhttp.send(null)
      > return;
      > }
      >
      > The behaviour is this:
      > - If I comment the eval line, the I can see the "after" and "before",
      > as well as the string returned by JSON from the PHP code.
      >
      > - If I un-comment the string, I'll see "after" and ths JSON string,
      > but the app will freeze after that.
      >
      > Thanks for any help.
      >
      > Pablo
      >
      >
      > --- In json@yahoogroups.com, Fang Yidong <fangyidong@> wrote:
      > >
      > >
      > > Show your source code of client side and server side
      > > to us, and maybe we can figure out what the problem
      > > is.
      > >
      > > --- rancioadams <comomolo@>:
      > >
      > > > Hi everyone. I'm new to this group so I'd like to
      > > > say hello. My name
      > > > is Pablo, despite of the dumb name in my email.
      > > >
      > > > My little AJAX app doesn't like the JSON encoded
      > > > strings returned from
      > > > the PHP part of the app. I mean, the PHP code
      > > > returns an apparently
      > > > correct string and I can see the data if I put the
      > > > JSON string
      > > > directly into the div element, but my javascript
      > > > hangs if I try to
      > > > eval the string. If I create an "identical" string
      > > > manually, my
      > > > javascript evaluates it correctly. This suggests the
      > > > JSON string
      > > > contains unprintable non-eval'able characters. I'm
      > > > about to give up
      > > > and write a little parsing code for this particular
      > > > need.
      > > >
      > > > Any ideas?
      > > >
      > > > Pablo
      > > >
      > > > PS: When I'm finished with this little job, I might
      > > > help with the
      > > > Spanish translations of the JSON pages.
      > > >
      > > >
      > > >
      > > >
      > > >
      > > >
      > > > ------------------------ Yahoo! Groups Sponsor
      > > > --------------------~-->
      > > > You can search right from your browser? It's easy
      > > > and it's free. See how.
      > > >
      > > http://us.click.yahoo.com/_7bhrC/NGxNAA/yQLSAA/1U_rlB/TM
      > > >
      > >
      --------------------------------------------------------------------~->
      > > >
      > > >
      > > >
      > > > Yahoo! Groups Links
      > > >
      > > >
      > > > json-unsubscribe@yahoogroups.com
      > > >
      > > >
      > > >
      > > >
      > > >
      > >
      > >
      > >
      > > ___________________________________________________________
      > > JSON: Action in AJAX!
      > >
      > > JSON - http://www.json.org
      > > JSON.simple - http://www.json.org/java/simple.txt
      > >
      > >
      > >
      > >
      > > ___________________________________________________________
      > > ÇÀ×¢ÑÅ»¢Ãâ·ÑÓÊÏä-3.5GÈÝÁ¿£¬20M¸½¼þ£¡
      > > http://cn.mail.yahoo.com
      > >
      >
    • Show all 13 messages in this topic