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

Re: [ydn-javascript] noob Autocomplete JSON with PHP

Expand Messages
  • Josh Sweeney
    I tried the suggested change which ended up looking as follows: $cityState[] = array( cityState = Austin, TX ); $cityState[] = array( cityState =
    Message 1 of 3 , Jan 29, 2009
      I tried the suggested change which ended up looking as follows:

              $cityState[] = array('cityState' => 'Austin, TX');
              $cityState[] = array('cityState' => 'Atlanta, GA');
              $cityState = json_encode($cityState);
              $cityState = '{"Response":{"Data":' . $cityState.'}}';

              echo $cityState;

      When I type in the input box, firebug now shows the response below but I am still not getting a drop box to select from under my input box.
      {"Response":{"Data":[{"cityState":"Austin, TX"},{"cityState":"Atlanta, GA"}]}}

      Any more ideas?

      From: Michael Lee <mikeizworkin@...>
      To: ydn-javascript@yahoogroups.com
      Sent: Tuesday, January 27, 2009 7:57:13 PM
      Subject: Re: [ydn-javascript] noob Autocomplete JSON with PHP


      $cityState = '"Response": {"Data":' . $cityState.' }';

      code should be

      $cityState = '{"Response" :{"Data": ' . $cityState.' }}';

      Notice the extra "{" and "}" characters at the beginning and end. That creates a valid JSON structure. What you were returning before isn't valid JSON and that's probably why nothing was "happening".

      Cheers :-)

      ----- Original Message -----
      From: "techfoozle" <techfoozle@yahoo. com>
      To: ydn-javascript@ yahoogroups. com
      Sent: Tuesday, January 27, 2009 2:58:33 PM GMT -05:00 US/Canada Eastern
      Subject: [ydn-javascript] noob Autocomplete JSON with PHP

      I was able to use the local javascript DataSource and get autocomplete
      to give me suggestions.

      Now I am trying to get it to work with an XHR Request and having some

      I have this as the js
      <script type="text/javascri pt">
      var dsXHR = new
      YAHOO.util.XHRDataS ource("<? =site_url( )?>ajax/search/ ");
      dsXHR.responseSchem a =
      resultsList : "Response.Data" ,
      fields : [
      { key: "cityState" }
      // simple location

      var myAutoComp = new
      YAHOO.widget. AutoComplete( "Location" ,"myContainer" , dsXHR);

      myAutoComp.generate Request =
      function(sQuery) {
      return sQuery;


      And for the PHP I have
      function cityStateAutocomple te()

      $cityState[] = array('cityState' => 'Austin, TX');
      $cityState[] = array('cityState' => 'Atlanta, GA');
      $cityState = json_encode( $cityState) ;
      $cityState = '"Response": {"Data":' . $cityState.' }';

      echo $cityState;


      In firebug I see that the response is returned but YUI isn't doing
      anything with it.

      The response is:
      "Response":{ "Data":[{ "cityState" :"Loganville,
      GA"},{"cityState" :"Atlanta, GA"}]}

      Can you tell me what I am not doing correctly?

    Your message has been successfully submitted and would be delivered to recipients shortly.