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

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

Expand Messages
  • rancioadams
    Here s the server code:
    Message 1 of 13 , May 27, 2006
    • 0 Attachment
      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
      >
    • rancioadams
      BTW: Here s the string returned by JSON, just in case: [ 160 , GENERAL DE
      Message 2 of 13 , May 27, 2006
      • 0 Attachment
        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
        > >
        >
      • Fang Yidong
        ... OBRA , HORMIGONERAS , REF. , TIPO , CORRIENTE , P /HORA , LITRO , , , , , EURO /DIA , SEG. /DIA ,null,null,null,null] ... It seems that there s a CR or
        Message 3 of 13 , May 27, 2006
        • 0 Attachment
          --- rancioadams <comomolo@...>:

          > 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]
          >

          It seems that there's a CR or LN between 'GENERAL DE'
          and 'OBRA' in the result. In JSON , controls should be
          escaped, and CR should be escaped as '\r' and LN
          should be escaped as '\n'.Choose a correct
          implementation of JSON encoder.


          > 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
          > > > >
          > > > >
          > > > >
          > > > >
          > > > >
          > > >
          > > >
          > > >
          > > >
          >
          ___________________________________________________________

          === message truncated ===



          ___________________________________________________________
          JSON: Action in AJAX!

          JSON - http://www.json.org
          JSON.simple - http://www.json.org/java/simple.txt







          ___________________________________________________________
          Mp3疯狂搜-新歌热歌高速下
          http://music.yahoo.com.cn/?source=mail_mailbox_footer
        • rancioadams
          Thanks but no, there s not a CR between GENERAL DE and OBRA . Just some problem with the posting here. Do the nulls at the end of the string pose a problem
          Message 4 of 13 , May 28, 2006
          • 0 Attachment
            Thanks but no, there's not a CR between "GENERAL DE" and "OBRA". Just
            some problem with the posting here.

            Do the nulls at the end of the string pose a problem to the encoder?

            I'm using the enconder found here:
            http://pear.php.net/pepr/pepr-proposal-show.php?id=198

            Regards.

            p

            --- In json@yahoogroups.com, Fang Yidong <fangyidong@...> wrote:
            >
            >
            > --- rancioadams <comomolo@...>:
            >
            > > 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]
            > >
            >
            > It seems that there's a CR or LN between 'GENERAL DE'
            > and 'OBRA' in the result. In JSON , controls should be
            > escaped, and CR should be escaped as '\r' and LN
            > should be escaped as '\n'.Choose a correct
            > implementation of JSON encoder.
            >
            >
            > > 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
            > > > > >
            > > > > >
            > > > > >
            > > > > >
            > > > > >
            > > > >
            > > > >
            > > > >
            > > > >
            > >
            > ___________________________________________________________
            >
            > === message truncated ===
            >
            >
            >
            > ___________________________________________________________
            > JSON: Action in AJAX!
            >
            > JSON - http://www.json.org
            > JSON.simple - http://www.json.org/java/simple.txt
            >
            >
            >
            >
            >
            >
            >
            > ___________________________________________________________
            > Mp3·è¿ñËÑ-иèÈȸè¸ßËÙÏÂ
            > http://music.yahoo.com.cn/?source=mail_mailbox_footer
            >
          • rancioadams
            Thanks but no, there s not a CR between GENERAL DE and OBRA . Just some problem with the posting here. Do the nulls at the end of the string pose a problem
            Message 5 of 13 , May 28, 2006
            • 0 Attachment
              Thanks but no, there's not a CR between "GENERAL DE" and "OBRA". Just
              some problem with the posting here.

              Do the nulls at the end of the string pose a problem to the encoder?

              I'm using the encoder found here:
              http://pear.php.net/pepr/pepr-proposal-show.php?id=198

              Regards.

              p

              --- In json@yahoogroups.com, Fang Yidong <fangyidong@...> wrote:
              >
              >
              > --- rancioadams <comomolo@...>:
              >
              > > 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]
              > >
              >
              > It seems that there's a CR or LN between 'GENERAL DE'
              > and 'OBRA' in the result. In JSON , controls should be
              > escaped, and CR should be escaped as '\r' and LN
              > should be escaped as '\n'.Choose a correct
              > implementation of JSON encoder.
              >
              >
              > > 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
              > > > > >
              > > > > >
              > > > > >
              > > > > >
              > > > > >
              > > > >
              > > > >
              > > > >
              > > > >
              > >
              > ___________________________________________________________
              >
              > === message truncated ===
              >
              >
              >
              > ___________________________________________________________
              > JSON: Action in AJAX!
              >
              > JSON - http://www.json.org
              > JSON.simple - http://www.json.org/java/simple.txt
              >
              >
              >
              >
              >
              >
              >
              > ___________________________________________________________
              > Mp3·è¿ñËÑ-иèÈȸè¸ßËÙÏÂ
              > http://music.yahoo.com.cn/?source=mail_mailbox_footer
              >
            • MPCM
              Is there a place you can post your sample string at a website. So that these groups can t mangle it? -- Matthew P. C. Morley MPCM Technologies Inc. [Non-text
              Message 6 of 13 , May 28, 2006
              • 0 Attachment
                Is there a place you can post your sample string at a website. So that these
                groups can't mangle it?

                --
                Matthew P. C. Morley
                MPCM Technologies Inc.


                [Non-text portions of this message have been removed]
              • Fang Yidong
                I know what the problem is now.The line in your client code: var tabla = eval(xmlhttp.responseText); should be: var tabla = eval( ( +xmlhttp.responseText+ ) );
                Message 7 of 13 , May 28, 2006
                • 0 Attachment
                  I know what the problem is now.The line in your client
                  code:

                  var tabla = eval(xmlhttp.responseText);

                  should be:

                  var tabla = eval("("+xmlhttp.responseText+")");



                  --- rancioadams <comomolo@...>:

                  > Thanks but no, there's not a CR between "GENERAL DE"
                  > and "OBRA". Just
                  > some problem with the posting here.
                  >
                  > Do the nulls at the end of the string pose a problem
                  > to the encoder?
                  >
                  > I'm using the enconder found here:
                  >
                  http://pear.php.net/pepr/pepr-proposal-show.php?id=198
                  >
                  > Regards.
                  >
                  > p
                  >
                  > --- In json@yahoogroups.com, Fang Yidong
                  > <fangyidong@...> wrote:
                  > >
                  > >
                  > > --- rancioadams <comomolo@...>:
                  > >
                  > > > 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]
                  > > >
                  > >
                  > > It seems that there's a CR or LN between 'GENERAL
                  > DE'
                  > > and 'OBRA' in the result. In JSON , controls
                  > should be
                  > > escaped, and CR should be escaped as '\r' and LN
                  > > should be escaped as '\n'.Choose a correct
                  > > implementation of JSON encoder.
                  > >
                  > >
                  > > > 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
                  >
                  === message truncated ===



                  ___________________________________________________________
                  JSON: Action in AJAX!

                  JSON - http://www.json.org
                  JSON.simple - http://www.json.org/java/simple.txt


                  __________________________________________________
                  赶快注册雅虎超大容量免费邮箱?
                  http://cn.mail.yahoo.com
                • rancioadams
                  Hi Fang, I really appreciate your efforts but I tried that too and it didn t work (as a matter of fact, I believe the parenthesis are just a safety measure ).
                  Message 8 of 13 , May 28, 2006
                  • 0 Attachment
                    Hi Fang,

                    I really appreciate your efforts but I tried that too and it didn't
                    work (as a matter of fact, I believe the parenthesis are just a
                    "safety measure").

                    Now I've been able to solve the problem and what's happening is hard
                    to believe for me but I've been testing it thoroughly this afternoon.

                    This is what's going on:

                    The PHP part is sending a string with 67 characters in front and 2
                    characters at the end. IE, instead of the expected string, I get
                    something like this:

                    garbage(67 char) + string + garbage(67 char)

                    I don't have a clue of what produces these characters or what they
                    content, but after much testing with string.length and
                    string.substring, I came to the conclusion that I have to pass the
                    data through the following filter:

                    var datos = xmlhttp.responseText;

                    datos = datos.substring(67,datos.length-2);

                    If I do that, I get the proper string that will eval'uate properly.
                    This has nothing to do with the JSON.php stuff. Even if I don't use
                    JSON at all, I stil get all that garbage in the same exact numbers.

                    Do you have any idea of what's going on here?

                    I'm working on UTF-8 all the time, but I don't think this should make
                    the difference, does it?

                    I'll leave it like that (since it's working), but I would really want
                    to know what are all those garbage characters, who puts them there and
                    what are they intended for or if there's a bug somewhere that can be
                    causing that.

                    Regards,

                    Pablo



                    --- In json@yahoogroups.com, Fang Yidong <fangyidong@...> wrote:
                    >
                    >
                    > I know what the problem is now.The line in your client
                    > code:
                    >
                    > var tabla = eval(xmlhttp.responseText);
                    >
                    > should be:
                    >
                    > var tabla = eval("("+xmlhttp.responseText+")");
                    >
                    >
                    >
                    > --- rancioadams <comomolo@...>:
                    >
                    > > Thanks but no, there's not a CR between "GENERAL DE"
                    > > and "OBRA". Just
                    > > some problem with the posting here.
                    > >
                    > > Do the nulls at the end of the string pose a problem
                    > > to the encoder?
                    > >
                    > > I'm using the enconder found here:
                    > >
                    > http://pear.php.net/pepr/pepr-proposal-show.php?id=198
                    > >
                    > > Regards.
                    > >
                    > > p
                    > >
                    > > --- In json@yahoogroups.com, Fang Yidong
                    > > <fangyidong@> wrote:
                    > > >
                    > > >
                    > > > --- rancioadams <comomolo@>:
                    > > >
                    > > > > 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]
                    > > > >
                    > > >
                    > > > It seems that there's a CR or LN between 'GENERAL
                    > > DE'
                    > > > and 'OBRA' in the result. In JSON , controls
                    > > should be
                    > > > escaped, and CR should be escaped as '\r' and LN
                    > > > should be escaped as '\n'.Choose a correct
                    > > > implementation of JSON encoder.
                    > > >
                    > > >
                    > > > > 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
                    > >
                    > === message truncated ===
                    >
                    >
                    >
                    > ___________________________________________________________
                    > JSON: Action in AJAX!
                    >
                    > JSON - http://www.json.org
                    > JSON.simple - http://www.json.org/java/simple.txt
                    >
                    >
                    > __________________________________________________
                    > ¸Ï¿ì×¢²áÑÅ»¢³¬´óÈÝÁ¿Ãâ·ÑÓÊÏä?
                    > http://cn.mail.yahoo.com
                    >
                  • rancioadams
                    Sure, but please read my last post. I will try to decipher what the string content is. Not tonight (tomorrow I must show some working code!), but surely
                    Message 9 of 13 , May 28, 2006
                    • 0 Attachment
                      Sure, but please read my last post.

                      I will try to decipher what the string content is. Not tonight
                      (tomorrow I must show some working code!), but surely tomorrow night
                      or Tuesday.

                      If you think you want to work on it a bit, I can upload my files,
                      including the database in CSV format, to some FTP server. I just don't
                      dare to ask you guys for so much!

                      Pablo

                      --- In json@yahoogroups.com, MPCM <WickedLogic@...> wrote:
                      >
                      > Is there a place you can post your sample string at a website. So
                      that these
                      > groups can't mangle it?
                      >
                      > --
                      > Matthew P. C. Morley
                      > MPCM Technologies Inc.
                      >
                      >
                      > [Non-text portions of this message have been removed]
                      >
                    • Mert Sakarya
                      I recommend using Fiddler (free) or HttpWatcher for examining what s going on between server and the client. These tools are for Windows (HttpWatcher works as
                      Message 10 of 13 , May 28, 2006
                      • 0 Attachment
                        I recommend using Fiddler (free) or HttpWatcher for examining what's going on between server and the client.
                        These tools are for Windows (HttpWatcher works as Internet Explorer Addin, Fiddler captures IO from programs that uses WinInet.dll like Internet Explorer)
                        May be the Encoding header and the real stream are different.



                        To: json@yahoogroups.comFrom: comomolo@...: Sun, 28 May 2006 17:47:25 +0000Subject: Re:[json] My javascript app freezes at eval'uating JSON string returnedHi Fang,I really appreciate your efforts but I tried that too and it didn'twork (as a matter of fact, I believe the parenthesis are just a"safety measure").Now I've been able to solve the problem and what's happening is hardto believe for me but I've been testing it thoroughly this afternoon.This is what's going on:The PHP part is sending a string with 67 characters in front and 2characters at the end. IE, instead of the expected string, I getsomething like this:garbage(67 char) + string + garbage(67 char)I don't have a clue of what produces these characters or what theycontent, but after much testing with string.length andstring.substring, I came to the conclusion that I have to pass thedata through the following filter:var datos = xmlhttp.responseText;datos = datos.substring(67,datos.length-2);If I do that, I get the proper string that will eval'uate properly.This has nothing to do with the JSON.php stuff. Even if I don't useJSON at all, I stil get all that garbage in the same exact numbers.Do you have any idea of what's going on here?I'm working on UTF-8 all the time, but I don't think this should makethe difference, does it?I'll leave it like that (since it's working), but I would really wantto know what are all those garbage characters, who puts them there andwhat are they intended for or if there's a bug somewhere that can becausing that.Regards,Pablo--- In json@yahoogroups.com, Fang Yidong <fangyidong@...> wrote:>> > I know what the problem is now.The line in your client> code:> > var tabla = eval(xmlhttp.responseText);> > should be:> > var tabla = eval("("+xmlhttp.responseText+")");> > > > --- rancioadams <comomolo@...>:> > > Thanks but no, there's not a CR between "GENERAL DE"> > and "OBRA". Just> > some problem with the posting here.> > > > Do the nulls at the end of the string pose a problem> > to the encoder?> > > > I'm using the enconder found here:> >> http://pear.php.net/pepr/pepr-proposal-show.php?id=198> > > > Regards.> > > > p> > > > --- In json@yahoogroups.com, Fang Yidong> > <fangyidong@> wrote:> > >> > > > > > --- rancioadams <comomolo@>:> > > > > > > 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]> > > > > > > > > > It seems that there's a CR or LN between 'GENERAL> > DE'> > > and 'OBRA' in the result. In JSON , controls> > should be> > > escaped, and CR should be escaped as '\r' and LN> > > should be escaped as '\n'.Choose a correct> > > implementation of JSON encoder.> > > > > > > > > > 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> > > === message truncated ===> > > > ___________________________________________________________ > JSON: Action in AJAX!> > JSON - http://www.json.org> JSON.simple - http://www.json.org/java/simple.txt> > > __________________________________________________> ¸Ï¿ì×¢²áÑÅ»¢³¬´óÈÝÁ¿Ãâ·ÑÓÊÏä?> http://cn.mail.yahoo.com>
                        SPONSORED LINKS



                        Programming languages
                        Format
                        Computer security

                        Computer training
                        Large format
                        Cover letter formats


                        YAHOO! GROUPS LINKS

                        Visit your group "json" on the web.
                        To unsubscribe from this group, send an email to: json-unsubscribe@yahoogroups.com
                        Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.



                        _________________________________________________________________
                        Join the next generation of Hotmail and you could win the adventure of a lifetime
                        http://www.imagine-msn.com/minisites/sweepstakes/mail/register.aspx

                        [Non-text portions of this message have been removed]
                      • rancioadams
                        Sorry I made a typo down there (is there any way to edit posts?) garbage(67 char) + string + garbage(67 char) should be: garbage(67 char) + string + garbage(2
                        Message 11 of 13 , May 28, 2006
                        • 0 Attachment
                          Sorry I made a typo down there (is there any way to edit posts?)

                          garbage(67 char) + string + garbage(67 char)

                          should be:

                          garbage(67 char) + string + garbage(2 char)

                          p

                          --- In json@yahoogroups.com, "rancioadams" <comomolo@...> wrote:
                          >
                          > Hi Fang,
                          >
                          > I really appreciate your efforts but I tried that too and it didn't
                          > work (as a matter of fact, I believe the parenthesis are just a
                          > "safety measure").
                          >
                          > Now I've been able to solve the problem and what's happening is hard
                          > to believe for me but I've been testing it thoroughly this afternoon.
                          >
                          > This is what's going on:
                          >
                          > The PHP part is sending a string with 67 characters in front and 2
                          > characters at the end. IE, instead of the expected string, I get
                          > something like this:
                          >
                          > garbage(67 char) + string + garbage(67 char)
                          >
                          > I don't have a clue of what produces these characters or what they
                          > content, but after much testing with string.length and
                          > string.substring, I came to the conclusion that I have to pass the
                          > data through the following filter:
                          >
                          > var datos = xmlhttp.responseText;
                          >
                          > datos = datos.substring(67,datos.length-2);
                          >
                          > If I do that, I get the proper string that will eval'uate properly.
                          > This has nothing to do with the JSON.php stuff. Even if I don't use
                          > JSON at all, I stil get all that garbage in the same exact numbers.
                          >
                          > Do you have any idea of what's going on here?
                          >
                          > I'm working on UTF-8 all the time, but I don't think this should make
                          > the difference, does it?
                          >
                          > I'll leave it like that (since it's working), but I would really want
                          > to know what are all those garbage characters, who puts them there and
                          > what are they intended for or if there's a bug somewhere that can be
                          > causing that.
                          >
                          > Regards,
                          >
                          > Pablo
                          >
                          >
                          >
                          > --- In json@yahoogroups.com, Fang Yidong <fangyidong@> wrote:
                          > >
                          > >
                          > > I know what the problem is now.The line in your client
                          > > code:
                          > >
                          > > var tabla = eval(xmlhttp.responseText);
                          > >
                          > > should be:
                          > >
                          > > var tabla = eval("("+xmlhttp.responseText+")");
                          > >
                          > >
                          > >
                          > > --- rancioadams <comomolo@>:
                          > >
                          > > > Thanks but no, there's not a CR between "GENERAL DE"
                          > > > and "OBRA". Just
                          > > > some problem with the posting here.
                          > > >
                          > > > Do the nulls at the end of the string pose a problem
                          > > > to the encoder?
                          > > >
                          > > > I'm using the enconder found here:
                          > > >
                          > > http://pear.php.net/pepr/pepr-proposal-show.php?id=198
                          > > >
                          > > > Regards.
                          > > >
                          > > > p
                          > > >
                          > > > --- In json@yahoogroups.com, Fang Yidong
                          > > > <fangyidong@> wrote:
                          > > > >
                          > > > >
                          > > > > --- rancioadams <comomolo@>:
                          > > > >
                          > > > > > 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]
                          > > > > >
                          > > > >
                          > > > > It seems that there's a CR or LN between 'GENERAL
                          > > > DE'
                          > > > > and 'OBRA' in the result. In JSON , controls
                          > > > should be
                          > > > > escaped, and CR should be escaped as '\r' and LN
                          > > > > should be escaped as '\n'.Choose a correct
                          > > > > implementation of JSON encoder.
                          > > > >
                          > > > >
                          > > > > > 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
                          > > >
                          > > === message truncated ===
                          > >
                          > >
                          > >
                          > > ___________________________________________________________
                          > > JSON: Action in AJAX!
                          > >
                          > > JSON - http://www.json.org
                          > > JSON.simple - http://www.json.org/java/simple.txt
                          > >
                          > >
                          > > __________________________________________________
                          > > ¸Ï¿ì×¢²áÑÅ»¢³¬´óÈÝÁ¿Ãâ·ÑÓÊÏä?
                          > > http://cn.mail.yahoo.com
                          > >
                          >
                        Your message has been successfully submitted and would be delivered to recipients shortly.