Elankeeran
Elankeeran

Reputation: 6184

I need solution for jquery ajax autocomplete in php

I have used jquery for javascript in my project I need to create autocomplete with php ajax

I am using below code

$("input#txtaddkey").autocomplete({
   source: ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby"]
  });

And I have taken some code as below

$("input#txtaddkey").autocomplete({
   url: 'keyword.php',
     width: 300,
     max: 10,
     delay: 100,
     cacheLength: 1,
     scroll: false,
     highlight: false
  });

But I am not understand how above code will work and How to get the query string from php file.

Please guide me.

Upvotes: 0

Views: 273

Answers (2)

Elankeeran
Elankeeran

Reputation: 6184

I got the answer..

Query string will pass as $_GET['term'].

A request object, with a single property called "term", which refers to the value currently in the text input. For example, when the user entered "new yo" in a city field, the Autocomplete term will equal "new yo".

Thanks every one.

http://docs.jquery.com/UI/Autocomplete

Upvotes: 0

Nik Chankov
Nik Chankov

Reputation: 6047

Why don't you see at the Autocomplete page.

Basically your server response (the result in the keyword.php need to be formatted as JSON. i.e.

[ { "id": 1, "label": "text 1", "value": "val 1" }, { "id": 2, "label": "text2", "value": "val 2" } ]

Check also json_encode

Upvotes: 2

Related Questions