How to pass a remote source data from Python CGI to jquery autocomplete? I am ab
ID: 3916926 • Letter: H
Question
How to pass a remote source data from Python CGI to jquery autocomplete? I am able to hard code the value via array but not able to figure out the method to use a cgi script data. Thanks! How to pass a remote source data from Python CGI to jquery autocomplete? I am able to hard code the value via array but not able to figure out the method to use a cgi script data. Thanks! How to pass a remote source data from Python CGI to jquery autocomplete? I am able to hard code the value via array but not able to figure out the method to use a cgi script data. Thanks!Explanation / Answer
Yes, it is possible to pass a remote source data from python CGI to jquery autocomplete. There are various ways to manage this piece of work. There are few plugins (I prefer pengoworks) also available which can help you to achieve this, such as restrict your dropdown to have N number of outcome or pre-populate text boxes as user types etc.
1. You can pass the URL of the controller which would handle the requests and the controller need to read request variables to generate the outcome and return it.
2. When you enter some value in the Input field, it sets off the autocomplete and it, in turn, creates an ajax call to given handler function; passing the parameter value. The handler needs to get the value of the parameter to process and ensure it displays the correct items in the drop-down. When related ajax call returns the drop-down value is shown to end-user and selection made by end-user is considered as the value of your Input field.
please note the samples below :
Let's say your form would require a field as below :
<INPUT id= "sampleInput" name="sampleInpt" class="sample_input" type="text" />
Autocomplete will look like as below:
$('#sampleInput").autocomplete("/app/handlers/sampleInputData", {minItemsToShow=5, maxItemsToShow=10, onSelect: function(item) { ......}});
You may define the sampleInputData function in your app as you would require - e.g.
def sampleInputData():
q=requests.vars.q
Hope this answers your query. Happy coding!
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.