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

Re: [ydn-javascript] Re: DataTable "Data Error" with JSON

Expand Messages
  • Satyam
    In the responseSchema.resultsList you are saying that the results are under jb_table . That is no so, the data is straight out of the root. Before echoing
    Message 1 of 4 , Mar 30, 2009
    • 0 Attachment
      In the responseSchema.resultsList you are saying that the results are
      under "jb_table". That is no so, the data is straight out of the root.
      Before echoing $encoded, prefix it with {jb_table: and sufix it with
      an extra curly brace.

      Satyam

      bamirzada escribió:
      > I was playing around with XML and JSON, and changed the Datasource type back to JSON with still the same problem.
      >
      > Also, my PHPInfo informs me that JSON is enabled:
      > json support enabled
      > json version 1.2.1
      >
      > My PHP file is returning the following JSON:
      >
      > [{"job_title":"Senior iPhone Developer","zip":"92101","city":"San Jose","zlat":"32.7211"},{"job_title":"Principal Engineer - Google Android Applications","zip":"10027","city":"New York","zlat":"40.812242"},{"job_title":"Mobile Developer - Multiple Platforms","zip":"92101","city":"San Diego","zlat":"32.7211"},{"job_title":"iPhone Game Engineer","zip":"92008","city":"Carlsbad","zlat":"33.016928"},{"job_title":"Cellular Handset Engineer","zip":"7974","city":"New York","zlat":"0"},{"job_title":"Senior Interaction Designer","zip":"10027","city":"New York","zlat":"40.812242"},{"job_title":"Visual Designer- iPhone Games","zip":"95112","city":"Palo Alto","zlat":"37.37004"},{"job_title":"iPhone Software Engineer","zip":"95014","city":"Cupertino","zlat":"37.189396"},{"job_title":"iPhone Game Programmer - Mid Level","zip":"92101","city":"San Diego","zlat":"32.7211"},{"job_title":"iPhone Apps Developer- Award Winning Dev\/Design Firm","zip":"94107","city":"San Francisco","zlat":"37.769029"},{"job_title":"Senior iPhone Engineer","zip":"95112","city":"Palo Alto","zlat":"37.37004"},{"job_title":"iphone developer ","zip":"2000","city":"Sydney","zlat":"0"}]
      >
      > Any specific suggestions ??
      >
      > --- In ydn-javascript@yahoogroups.com, Satyam <satyam@...> wrote:
      >
      >> First, it would be good to tell it that the data comes in TYPE_JSON
      >> instead of TYPE_XML
      >>
      >> Second, if there is any second, your PHP codes says little about how
      >> your data will be received in the browser. If you don't have it yet,
      >> load Firefox and then the Firebug Add-on. Try the same program with
      >> Firebug enabled and look in the Net tab to see what actually did reach
      >> the browser. Perhaps you don't have JSON support compiled into your
      >> interpreter and all you are getting is a nicely formatted HTML page
      >> telling you about that.
      >>
      >> Finally, this article, and others referenced in that index, might be useful:
      >>
      >> http://satyam.com.ar/yui/#phpjson
      >>
      >> Satyam
      >>
      >>
      >> bamirzada escribió:
      >>
      >>> Hello,
      >>> I have an issue that is driving me nuts.
      >>>
      >>> I keep getting a "Data Error" error when I try to bind my JSON from my PHP file on a YUI Datatable object.
      >>>
      >>> Below is my code. Any help is much appreciated.
      >>>
      >>>
      >>> <script type="text/javascript">
      >>> YAHOO.util.Event.addListener(window, "load", function() {
      >>> YAHOO.example.XHR_JSON = new function() {
      >>>
      >>> var myColumnDefs = [
      >>> {key:"job_title"},
      >>> {key:"zip"},
      >>> {key:"city"},
      >>> {key:"zlat"}
      >>> ];
      >>>
      >>> this.myDataSource = new YAHOO.util.DataSource("example.php?");
      >>> this.myDataSource.connMethodPost = true;
      >>> this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_XML;
      >>> this.myDataSource.responseSchema = {
      >>> resultsList: "jb_table",
      >>> fields: ["job_title","zip","city","zlat"]
      >>> };
      >>>
      >>> this.myDataTable = new YAHOO.widget.DataTable("json2", myColumnDefs, this.myDataSource);
      >>>
      >>> };
      >>> });
      >>> </script>
      >>>
      >>> </head>
      >>> <body class="yui-skin-sam">
      >>>
      >>> <div id="json2"></div>
      >>>
      >>> </body>
      >>> </html>
      >>>
      >>> =====================
      >>> PHP FILE:
      >>> =====================
      >>>
      >>> $sql = mysql_query("SELECT job_title, zip, city, zlat FROM jb_table");
      >>>
      >>> $encodable = array();
      >>>
      >>> while($obj = mysql_fetch_object($sql))
      >>> {
      >>> $encodable[] = $obj;
      >>> }
      >>>
      >>> $encoded = json_encode($encodable);
      >>>
      >>>
      >>> echo $encoded;
      >>>
      >>>
      >>> mysql_close();
      >>> ?>
      >>>
      >>>
      >>>
      >>> ------------------------------------
      >>>
      >>> Yahoo! Groups Links
      >>>
      >>>
      >>>
      >>> ------------------------------------------------------------------------
      >>>
      >>>
      >>> No virus found in this incoming message.
      >>> Checked by AVG - www.avg.com
      >>> Version: 8.5.285 / Virus Database: 270.11.31/2029 - Release Date: 03/29/09 16:56:00
      >>>
      >>>
      >>>
      >
      >
      >
      >
      > ------------------------------------
      >
      > Yahoo! Groups Links
      >
      >
      >
      > ------------------------------------------------------------------------
      >
      >
      > No virus found in this incoming message.
      > Checked by AVG - www.avg.com
      > Version: 8.5.285 / Virus Database: 270.11.32/2030 - Release Date: 03/30/09 08:40:00
      >
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.