Hi all!
I use those two lovely guys:
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.3.1.min.js"></script>
I've implemented a search in my jQuery mobile little application that searchs for data in a mysql database using php on the server side.
I use this to get Italian cities names so the user can insert in my form only correct data.
The php works without problems and can be checked easily adding to the end of this url a few letters:
http://193.206.249.249:10000/core/php/getselezionecomuni.php?nome_comune=It gives back json data correctly.
The strangely acting part (at least imho) is the jquery mobile one.
Here's the function:
- function getSceltaComuni() {
- $("input:jqmData(type='search')").keyup(function() {
- var ul_ricerca_comune_input = $(this).val();
- var dataString = 'nome_comune='+ ul_ricerca_comune_input;
- console.log (ul_ricerca_comune_input.length);
- console.log (ul_ricerca_comune_input);
- if (ul_ricerca_comune_input.length > 1)
- //If length of input field greater than 1
- {
- $.getJSON(serviceURL + 'getselezionecomuni.php?'+dataString, function(data) {
- $('#ul_ricerca_comune li').remove();
- comuni = data.items;
- console.log (comuni);
- console.log ("eseguito");
- // La funzione sottostante trasforma il testo tutto maiuscolo in testo con solo la prima lettera maiuscola
- $.each(comuni, function(index, comuni) {
- var strcomune = (comuni.nome_comune);
- strcomune = strcomune.toLowerCase().replace(/\b[a-z]/g, function(letter) {
- return letter.toUpperCase();
- });
- var id = (comuni.id_comune);
- // La funzione sottostante crea dinamicamente la lista dei clienti
- $('#ul_ricerca_comune').append('<li>' + strcomune + '</li>');
- // $('input[data-type="search"]').val("");
- // $('input[data-type="search"]').trigger("change");
- });
- $('#ul_ricerca_comune').listview('refresh');
- // Questa funzione resetta il datafilter una volta effettuata una scelta
- sceltaComune();
- });
I can say it almost works but it only gives back results from the database only when the result is a single row.
You can try the faulty behaviour here:
http://193.206.249.249:10000/core/inserimento_struttura.htmlIf you enter the letters of roma, as example, you get the list correctly populated only when you finish enter letters.
I really can't understand why.
I've tried to be accurate but forgive me if anything's missing: I'll write back as soon as you have further questions.
Thank you all for your time and patience.