3

Currently I am using plugin called jQuery TagHandler. How can I link with database to listout data. I have listed code samples below. Below code are not working. Please correct me.

js

$("#array_tag_handler").tagHandler({
      getData: { id: '1', type: 'user' },
      getURL: '/tag/interest',
      updateData: { id: 'user234', type: 'user' },
      updateURL: '/ajaxtest/update',
      autocomplete: true,
      autoUpdate: true
  });

PHP

$select_pos     = "SELECT title FROM homegrid";
    $select_exec    = mysql_query($select_pos);
    $return_data    = array();
    while($dataFromDB = mysql_fetch_assoc($select_exec)) {
        $return_data[]= array(
            "title"        => $dataFromDB['title'],
        );
    }
    header('Content-Type: application/json');
    echo json_encode($return_data);
Sarath TS
  • 2,432
  • 6
  • 32
  • 79
  • 2
    If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Sep 01 '15 at 12:22
  • What error you get?? What file structure you have?? Have you specified correct URL?? – Indrasinh Bihola Sep 01 '15 at 12:31
  • @IndrasinhBihola, Url is correct. I have getting response. Firebug shows "[{"title":"INTEREST"},{"title":"SKILLS"},{"title":"LANGUAGES"}]". But firebug shows another message "TypeError: data.availableTags is undefined if (data.availableTags.length) {" – Sarath TS Sep 01 '15 at 12:41
  • You need to provide json array named like this `{'availableTags':[{"title":"INTEREST"},{"title":"SKILLS"},{"title":"LANGUAGES"}]}` that's the issue. – Indrasinh Bihola Sep 01 '15 at 12:54
  • @IndrasinhBihola, Okay I got the response. Firebug console shows like "{"availableTags":[{"title":"Music"},{"title":"Reading"}]}". But when the response data is print using alert function shows " [object Object],[object Object] " – Sarath TS Sep 02 '15 at 04:59
  • So what's your issue now?? – Indrasinh Bihola Sep 02 '15 at 05:02
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/88530/discussion-between-indrasinh-bihola-and-sam-sam). – Indrasinh Bihola Sep 02 '15 at 05:05

1 Answers1

1

I have removed keys from my response {"availableTags":[{"title":"Music"},{"title":"Reading"}]}

Now the response look likes {"availableTags":["Music","Reading"],"assignedTags":["Music","Reading"]}

Sarath TS
  • 2,432
  • 6
  • 32
  • 79