I'm very new to AJAX calls - poked around the web for a few tutorials but still not quite getting successful at it.
The input field has an assigned ID of "idkey". The script is as follow:
$(document).on("keyup.autocomplete", "#idkey", function(){
var query = "q=" + $(this).val();
$.ajax({
url: 'api.php',
type: 'GET',
data: query,
dataType: 'json',
success: function(data) {
alert(data);
for (var i=0;i<data.length;i++) {
content = data[i].IDKey;
content += "<br>";
$(content).appendTo("#output");
// updateListing(data[x]);
}
}
});
});
On the server side, the api.php has an output of:
[{"IDKey":"30000001"},{"IDKey":"30000002"},{"IDKey":"30000004"}]
I am not sure why the alert(data)
would return [object Object], [object Object], [object Object]
. Any clue to why this is happening?
p/s: The php file has a header set to Content-Type: application/json
.