Search code examples
jquery-uiautocompletejsonp

How to use jquery ui autocomplete with different callback name with remote source


I am following this example to get JSONP data from remote server. jQuery append its own callback function while sending request like
http://url.com?callback=jQuery17107389513931702822_1332765044455&_=1332765051700

But the source is replying JSONP data in a fixed format as REPYL$queryString({"data":"abc"}) where queryString is the string for which reply is generated.
How to customize the options to support my own callback name? The error which I am getting right now is

 Uncaught ReferenceError: REPLY$querystring is not defined.

UPDATE

setting which worked for me are:

jsonp:false,
jsonpCallback:"CALL_BACK_NAME",

Solution

  • Use the jsonp setting in the .ajax request of the example you are using:

    jsonp

    Override the callback function name in a jsonp request. This value will be used instead of 'callback' in the 'callback=?' part of the query string in the url. So {jsonp:'onJSONPLoad'} would result in 'onJSONPLoad=?' passed to the server. As of jQuery 1.5, setting the jsonp option to false prevents jQuery from adding the "?callback" string to the URL or attempting to use "=?" for transformation. In this case, you should also explicitly set the jsonpCallback setting. For example, { jsonp: false, jsonpCallback: "callbackName" }

    jsonp: 'YOUR-CALLBACK-NAME'
    

    See the .ajax documentation