Mark Tower
Mark Tower

Reputation: 559

Bootstrap typeahead is not displaying AJAX results

Before asking I want to say that this is not a duplicated topic. I've already tried with:

...and many others, and I also read lots of Q&A, but none of them is what I am looking for.

All what I tried works with predefinite string sources, but when I do the next step: AJAX remote source, it is just showing no results on the dropdown list.

UPDATE - My code (don't understand why negative votes. Well written, well strucuted ;))

The html file

<html>
<head>
<link href="./bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css" />
</head>
<body>

<input id="myElement" class="typeahead" type="text">

<script src="./js/jquery.js"></script>
<script src="./bootstrap/js/bootstrap-typeahead.js"></script>
<script language="javascript">
$('#myElement').typeahead({
ajax: '/php/ajax.php'
});
</script>
[...]

The ajax.php file:

<?php
echo "[{ id: 1, name: 'Terry'}, { id: 2, name: 'Mark'}, { id: 3, name: 'Jack'}]";
?>

It's not an AJAX issue, because it is working in other cases at the same machine.
What may I try to fix it?, I am really crashing up my head since a few days. Thanks for reading.

Upvotes: 4

Views: 1907

Answers (2)

Ravinder Payal
Ravinder Payal

Reputation: 3031

hey set header of json in you php file use header('Content-Type: application/json');

for more info on header plese visit here(stackoverflow question) ad for example visit here(www.funnenjoy.com)

Upvotes: 0

Mark Tower
Mark Tower

Reputation: 559

People who vote negative without even knowing the right answer should think a bit before acting. If someone needs a real nice/working/magic autocomplete script, here wo go:

Real good Autocomplete Script

Description: This adds a pulldown menu of suggested values to a text field. The user can either click directly on a suggestion to enter it into the field, or navigate the list using the up and down arrow keys, selecting a value using the enter key. The values for the suggestion list are to provided as XML, or as JSON (by a PHP script, or similar).

Thanks those who made negative points disappear ;)

Upvotes: 5

Related Questions