Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Jquery Autocomplete PHP script

Posted on 2016-11-13
3
Medium Priority
?
133 Views
Last Modified: 2016-11-17
Hello,
Looking at the autocomplete example on Jquery UI, and I cant figure out how the source lets a variable to search the PHP script.

The code can be seen at:
view-source:https://jqueryui.com/resources/demos/autocomplete/remote.html


However, while I see where it sets the search.php, where does it set the variable (search.php?q=) to search the script?
0
Comment
Question by:Stephen Forlance
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 1000 total points
ID: 41885248
this file : https://code.jquery.com/ui/1.12.1/jquery-ui.js
contains multiple jquery ui widget, especially the autocomplete widget which start at line 5579

the part interested you is :
	_initSource: function() {
		var array, url,
			that = this;
		if ( $.isArray( this.options.source ) ) {
			array = this.options.source;
			this.source = function( request, response ) {
				response( $.ui.autocomplete.filter( array, request.term ) );
			};
		} else if ( typeof this.options.source === "string" ) {
			url = this.options.source;
			this.source = function( request, response ) {
				if ( that.xhr ) {
					that.xhr.abort();
				}
				that.xhr = $.ajax( {
					url: url,
					data: request,
					dataType: "json",
					success: function( data ) {
						response( data );
					},
					error: function() {
						response( [] );
					}
				} );
			};
		} else {
			this.source = this.options.source;
		}
	},

Open in new window


and some line after,  check line 6 :
	_search: function( value ) {
		this.pending++;
		this._addClass( "ui-autocomplete-loading" );
		this.cancelSearch = false;

		this.source( { term: value }, this._response() );
	}

Open in new window


this is where it define the data to be sent to the server : {term: value}
this autocomplete use "term" and not "q" unlike the other one
1
 
LVL 111

Assisted Solution

by:Ray Paseur
Ray Paseur earned 1000 total points
ID: 41885257
It doesn't use ?q= -- instead it uses ?term= for the argument.  This is done "under the covers" of the API.  The term is passed in the select function callback.

Docs here:
http://api.jqueryui.com/autocomplete/

Source here:
https://github.com/jquery/jquery-ui/blob/master/demos/autocomplete/search.php

Example here, showing JSON return values for "blue" birds:
https://jqueryui.com/resources/demos/autocomplete/search.php?term=blue
0
 
LVL 58

Expert Comment

by:Julian Hansen
ID: 41887411
If you want to see what is going on under the hood then open the sample page and press F12 to open the console.
Open the console tab and type something into the search box.

You should see something like this
ss92.jpg
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question