From cf55f66d259a0d9d9da98be151a9d8f7c2f420fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Drouyer?= Date: Sun, 27 May 2012 15:35:55 +0300 Subject: [PATCH] Adding urlData and urlMethod parameters, in order to allow this elements to be customized... --- jquery.jsonSuggest-2.js | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/jquery.jsonSuggest-2.js b/jquery.jsonSuggest-2.js index 3e6c45c..ec8fd0f 100644 --- a/jquery.jsonSuggest-2.js +++ b/jquery.jsonSuggest-2.js @@ -17,6 +17,8 @@ * url : [default ''] A URL that will return a JSON response. Called via $.getJSON, it is passed a * data dictionary containing the user typed search phrase. It must return a JSON string that * represents the array of results to display. + * urlData : [default {}] Additionnal data you send when requesting the url. + * urlMethod [default 'get'] Method of the request. * data : [default []]An array or JSON string representation of an array of data to search through. * Example of the array format is as follows: [ @@ -62,6 +64,8 @@ $.fn.jsonSuggest = function(settings) { var defaults = { url: '', + urlData: {}, + urlMethod: 'get', data: [], minCharacters: 1, maxResults: undefined, @@ -234,14 +238,20 @@ getJSONTimeout = window.clearTimeout(getJSONTimeout); getJSONTimeout = window.setTimeout(function() { - $.getJSON(settings.url, {search: text}, function(data) { - if (data) { - buildResults(data, text); - } - else { - $(results).html('').hide(); - } - }); + $.ajax({ + url: settings.url, + dataType: 'json', + data: $.extend(settings.urlData, {search: text}), + type: settings.urlMethod, + success: function(data) { + if (data) { + buildResults(data, text); + } + else { + $(results).html('').hide(); + } + } + }); }, 500); } }