jquery autocomplete issue server side

GionJh

I was hoping to make this example on jquery autocoplete work using a simple custom service I made up, but it's not working at all.

snippet:

$( "#city" ).autocomplete({
      source: function( request, response ) {
        $.ajax({
          url: "http://localhost:8085/TestJsonArrayAJAX/MyServlet",
          dataType: "jsonp",
          data: {
            q: request.term
          },
          success: function( data ) {

            alert("ciao");
            response( data );
          }
        });
      },
      minLength: 3,
      select: function( event, ui ) {
        log( ui.item ?
          "Selected: " + ui.item.label :
          "Nothing selected, input was " + this.value);
      },
      open: function() {
        $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
      },
      close: function() {
        $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
      }
    });

I noticed that the output of the original service is something like that:

jQuery1113013915240531787276_1443349161768(["Milaca, MN, United States","Milam, TX, United States");

meanwhile my services output is something like:

["Roma","Milano","Napoli","Palermo","Torino","Firenze","Pisa"]

because I though that a json array was enough and apparently is not.
Why is it not working, why a simple json array is not enough ?
Can you please help ?

EDIT:

implementing my service like this:

JSONArray jarr = new JSONArray();
        jarr.put("Roma");
        jarr.put("Milano");
        jarr.put("Napoli");
        jarr.put("Palermo");
        jarr.put("Torino");
        jarr.put("Firenze");
        jarr.put("Pisa");

String cb = request.getParameter("callback");
response.getOutputStream().print(cb+"("+jarr.toString()+");");

it works, but I still don't get why ??

ddw147

First in your code you dont need to call log function as you have not defined in current snipet

second change dataType: "jsonp", to dataType: "json",

you are providing input as json source not jsonp there is difference in them

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

jquery autocomplete issue server side

From Dev

jquery autocomplete with json issue

From Dev

Issue with AutoComplete of jQuery 1.9.1

From Dev

jQuery autocomplete enter key issue

From Dev

Pixabay jQuery autoComplete escape issue

From Dev

facing issue in jquery autocomplete with codeigniter

From Dev

Backgrid sort issue server side

From Dev

Rails jQuery-autocomplete client-side

From Dev

Rails jQuery-autocomplete client-side

From Dev

Razor Mvc 3 + Jquery autocomplete issue

From Dev

Is there browser compatibility issue with jquery autocomplete plugin?

From Dev

Jquery autocomplete no result append as dropdown child issue

From Dev

Issue with jQuery AutoComplete using JSON request

From Dev

server side issue for Push notification in ios

From Dev

React JS Server side issue - window not found

From Dev

Datatables server side processing pagination issue

From Dev

What is the server side issue that could cause the MethodNotAllowedHttpException

From Dev

Access array of server side in jQuery

From Dev

Access array of server side in jQuery

From Dev

Server side and Client side broswer width and bootstrap carousel issue in php

From Dev

How to Forcefully open autocomplete up side in jQuery UI

From Dev

Autocomplete issue

From Dev

Edit client-side jQuery from server-side NodeJs

From Dev

Div side by side issue

From Dev

Div side by side issue

From Dev

jquery Datatables server side processing with .net MVC

From Dev

Pass html string to server side with Jquery Ajax

From Dev

jQuery DataTables server-side processing with Java

From Dev

jQuery Datatables Server-side processing with WCF