I am basically building a common autocomplete search bar where a supposed user writes something, jQuery returns a list of suggestions and the user picks one.
My AJAX call looks like this:
var response = '';
var request = $.ajax({
url: "./includes/search_products.php",
type: "post",
dataType: "json",
data: serializedData,
success : function(text) {
response = text; // Gets the list of suggestions
}
});
The response is:
{"id":"2",
"companyId":"15",
"productTypeId":"1",
"label":"Alfa Romeo 159",
"price":"50000","comments":
"Random comment."}
How I set the .autocomplete:
request.done(function (){
console.log("Works.");
$('#product_search').autocomplete({
source: response,
minLength: 1,
select: function(event, ui) {
alert("yey");
}
});
});
The error message that I get is:
TypeError: this.source is not a function
I believe that a normal response should have less quotation marks, based on what the PHP json_encode() documentation says.
What's the problem? :(
.autocomplete?