jQuery autocomplete with jsonp
I´m trying to develope an autocomplete script using jQuery, now I´m in the last step.
I need to make a php page to call database, but the problem is I don´t know how the data(to be called to autocomplete)should lok like.
I know the script using something call "jsonp"
Here is the important lines that i want to show you, and my question is: How to build php code to make corectly data for this ?
function e(){f=-1;$("#ac_results").css("display",
"none")}function g(l,m){$.trim(p.val().toLowerCase())===l.toLowerCase()&&$.ajax({dataType:"jsonp",url:ac_server+"/"+encodeURIComponent(l)+"?callback=?&t="+m,success:function(k){var r=parseInt(k.t);
if(r>=s){s=r;t[l]=k.r;++w;b(k.r,l)}}})}var f=-1,h=0,n=i,s=0,t=[],w=0,p;return{bind:function(){p=$(a);if(typeof ac_server==="undefined")return c();p.attr("autocomplete","off");
p.bind("keyup",function(l){var m=(new Date).getTime(),k=$.trim($(this).val());
k=k.toLowerCase();if(!(l.keyCode in[40,38,13,27]||!n))if(k.length>
0)t[k]!==undefined?b(t[k],k):setTimeout(function(){g(k,m)},0);else e()});$(document).bind("keyup",function(l){if(l.keyCode===27)e();else if(l.keyCode!=undefined){$(".ac_active").attr("class","ac_inactive");switch(l.keyCode){case 40:if(f==-1)f=0;else if(++f>=h)f=0;$("#ac_opt_"+f).attr("class","ac_active");d($("#ac_opt_"+f));break;case 38:if(f==-1)f=h-1;else if(--f<0)f=h-1;$("#ac_opt_"+f).attr("class","ac_active");d($("#ac_opt_"+f));break;case 13:if(f!=-1){l=$("#ac_opt_"+f);l.length&&d(l,1)}else e()}}});
$("body").bind("click.autocompleter",function(){$(this).attr("id").indexOf("ac_")===-1&&e()});return this},fa:c}}("#ac_q");
(function(a){a.fn.U=function(b){var c=this;b=a.extend({A:"tactive",p:"tnactive",aa:".toptions",B:0,z:"href"},b||{});a(this).each(function(){var d=a(this).find(b.aa).children(),e;d.each(function(g){a(this).addClass(b.p);a(this).click(function(f){f.preventDefault();a(this).addClass(b.p);f=c.find(a(this).attr(b.z));if(f.length===0)throw"Could not find matching tab content for id: "+a(this).attr(b.z);e.removeClass(b.A).addClass(b.p);a(e.attr(b.z)).hide();a(this).removeClass(b.p).addClass(b.A);f.show();
e=a(this)});
if(g===b.B||g===0&&d.length-1<b.B){e=a(this);
a(this).trigger("click")}})})}})(jQuery);
thanks for further help
View Answers
June 21, 2011 at 8:43 PM
More explaination:
I really don´t know what is the variable i should make and what it should be look like. but here is something I tried but still not work.
//db connection detils
$host = "localhost";
$user = "root";
$password = "yourpasswordhere";
$database = "comments";
//make connection
$server = mysql_connect($host, $user, $password);
$connection = mysqlselectdb($database, $server);
//query the database
$query = mysql_query("SELECT * FROM comments");
//loop through and return results
for ($x = 0, $numrows = mysqlnumrows($query); $x < $numrows; $x++) {
$row = mysqlfetchassoc($query);
$comments[$x] = array("name" => $row["name"], "comment" => $row["comment"]);
}
//echo JSON to page
$response = $_GET["jsoncallback"] . "(" . json_encode($comments) . ")";
echo $response;
June 22, 2011 at 10:53 AM
June 22, 2011 at 11:28 AM
Hi, thanks, it´s not what I´m looking for.
This script that I post is a perfect script. Can be used like perfectly search engine like google.
I have got it from a web site, but what I have to do is finding the php code to give the correctly data.
It´s hard work i know, but i i found it, will be perfect.
June 22, 2011 at 11:46 AM
I mean if i found it, will be perfect, hehe but i not found it yet.
Related Tutorials/Questions & Answers:
jQuery autocomplete with jsonpjQuery autocomplete with jsonp I´m trying to develope an
autocomplete script using
jQuery, now I´m in the last step.
I need to make a php page... to
autocomplete)should lok like.
I know the script using something call "
jsonp jQuery UI Widget : Autocomplete
jQuery UI Widget :
Autocomplete
Query UI Widget :
Autocomplete
Using
autocomplete widget , you can add
autocomplete feature to your input
Advertisements
jQuery autocompletejQuery Autocomplete :
Autocomplete is a common feature available in lot of web... of
jquery.
This example shows A function for making
autocomplete text box with the help
of
jquery plugin and php/mysql .ADS_TO_REPLACE_1
In this example when we
jQuery Autocomplete fetch_object fatal error?jQuery Autocomplete fetch_object fatal error? I am consistently... of
Jquery Autocomplete box.
<script>
$(function() {
var... the database information etc.
http://www.roseindia.net/tutorial/ajax/
jquery autocompleteautocomplete I used
autocomplete from roseindida.net..
i am getting the
autocomplete is coming the retrieved values of database in the list..but when i select the value it is not displaying on the field..
and again i need
ModuleNotFoundError: No module named 'jsonp'ModuleNotFoundError: No module named '
jsonp' Hi,
My Python program is throwing following error:
ModuleNotFoundError: No module named '
jsonp'
How to remove the ModuleNotFoundError: No module named '
jsonp'
JQuery, use
jquery autocomplete JQuery using url of the doctors, use
jquery autocomplete JQueryJQuery how to use
jquery JqueryJquery I am new to
Jquery. Can anyone please tell me how to use
jquery plugins in html
jqueryjquery What are the
Jquery similarities or difference with other java script libraries
JQueryJQuery How i begin
JQuery and where i begin learning?
Please visit the following link:
JQuery Tutorials
Learn
Jquery from the above link. Here you will get lot of examples with illustration
jQueryjQuery Hi,
What is
jQuery and how it is used to develop Web applications?
Thanks
jqueryjquery how to display the leaves taken or holidays of the year or half working days in a calendar in some colors to identify the days using
jquery plugin
JQueryJQuery hi there,
I am just beginner for
jQuery and i want to know-what is
jQuery ? How it is better than JavaScript ?
jQuery... JavaScript :
Each
jQuery returns itself so you can chain them together(Chaining
JQueryJQuery how to create
jquery auto-complete textbox ? in which data come from database table?
Please visit the following link:
http://www.roseindia.net/tutorial/
jquery/autoSuggestTextbox.html
thank you
Autocomplete demo Autocomplete demo Thanks for the
autocomplete demo, it's working fine but results are showing in different fashion
Please see attached image. Can some one help me
Autocomplete demo Autocomplete demo Thanks for the
autocomplete demo, it's working fine but results are showing in different fashion
Please see attached image. Can some one help me
Autocomplete demo not workingAutocomplete demo not working Hi Team,
I am so happy with our examples on
Autocomplete , http://www.roseindia.net/tutorial/
jquery/autoComplete.html
I have copied the source files to my local machine and renamed
Autocomplete demo not workingAutocomplete demo not working Hi Team,
I am so happy with our examples on
Autocomplete , http://www.roseindia.net/tutorial/
jquery/autoComplete.html
I have copied the source files to my local machine and renamed
CAPXOUS AutoComplete
CAPXOUS
AutoComplete
CAPXOUS
AutoComplete is an AJAX suggestion component. You may have already
tasted this impressive feature on web sites like Google GMail or in business
jQuery Demos
jQuery Animate
jQuery autocomplete
jQuery...
jQuery Demos and quick examples
jQuery Demos
The best way to learn a new technology
autocomplete displaying multiple fieldsautocomplete displaying multiple fields How can I create an
autocomplete with three field (name, id, phone). Placing the phone field in the appropriate input field but selecting the name field into the 'calling' input box