views:

74

answers:

2

I know this is a bad title for my question but what i am trying to do is reply to Autocomplete http://docs.jquery.com/Plugins/Autocomplete#API%5FDocumentation

Instead of getting many elements i only receive "Array". I know this is obviously wrong bc of the way echo works but how do i echo in such a way this autocomplete works?

mydoc.html

$().ready(function() {
    $("#suggest3").autocomplete("reply.php", {
     multiple: true,
     mustMatch: true,
     autoFill: true
    });

});

reply.php

<?php
// Fill up array with names
$a[]="Anna";
$a[]="Brittany";
$a[]="Amanda";

  $response=$a;

echo $response;
?>
+4  A: 

Send it as JSON or convert it to a string- otherwise php just prints the object type.

JSON:

echo json_encode($a);

Array:

echo implode(',',$a);
Tonycore
String:echo implode(',',$a);
Tonycore
+1  A: 

Tonycore is right on with the json_encode() answer. I just wanted to add that when returning JSON it's also good to set the header correctly:

header("Content-type: application/json");
echo json_encode($a);
hlpiii