2

I have three URLs that return different JSON responses (say user mobiles, addresses and emails) being populated from different beans.

url='/mobile.do?username=x&password=y'
url='/email.do?username=x&password=y'
url='/address.do?username=x&password=y'

For the following autocomplete plugin (fcbkcomplete):

  <script type="text/javascript">
    $(document).ready(function(){                
        $("#mySelect").fcbkcomplete({
            json_url: "?!!",

        });
    });
</script>

Now I want to use these URLs to populate and add data to a single field rather than three different fields. Hence, somehow I need to mix these URL or something like this.

I was wondering what is the best way for this? Can we set more than one URLs or something?

SomeShinyObject
  • 7,581
  • 6
  • 39
  • 59
ComeRun
  • 921
  • 1
  • 20
  • 38
  • What do you mean by mix? Are they lists that can simply be added together? or does the data have to be joined somehow? – Fresheyeball Mar 22 '13 at 01:18
  • Fetching three different responses would be too much time... Couldn't you just return all three information from a single response (it will require to re-factor the backend code though) – Goran Mar 22 '13 at 01:20
  • Yes I need to load data from these urls, like having mobile, email and address in my result. – ComeRun Mar 22 '13 at 01:25
  • So you reckon its not a good idea to have 3 responses? Is it even possible? – ComeRun Mar 22 '13 at 01:25
  • I don't think you can find a resolution, since the ajax mechanism and this awkward situation. You have to send 3 ajax requests. – OQJF Mar 22 '13 at 01:28
  • Can I send 3 request and get one response for all? – ComeRun Mar 22 '13 at 01:31
  • I would probably make the first ajax request then on success make the 2nd and so on – Jay Rizzi Mar 22 '13 at 01:51
  • @Jay Rizzi , yeah, that's the way that I did it. Because I have to show or hide the progressing bar. – OQJF Mar 22 '13 at 02:10

1 Answers1

2

You could modify the plugin, by changing the function load_feed. This isn't tested, so might need some tweeking.

function load_feed(etext) {
    counter = 0;
    if (options.json_url_list && maxItems()) {
        if (options.cache && json_cache_object.get(etext)) {
            addMembers(etext);
            bindEvents();
        } else {
            getBoxTimeout++;
            var getBoxTimeoutValue = getBoxTimeout;
            setTimeout(function () {

                if (getBoxTimeoutValue != getBoxTimeout) return;

                var count = 0;
                var all_data = [];

                var finished = function () {
                    if (!isactive) return; // prevents opening the selection again after the focus is already off
                    json_cache_object.set(etext, 1);
                    bindEvents();
                };

                for (var i = 0; i < options.json_url_list.length; i++) {
                    $.getJSON(options.json_url_list[i], {
                        "tag": xssDisplay(etext)
                    }, function (data) {
                        addMembers(etext, data);
                        count += 1;
                        if (count === options.json_url_list.length) finished();
                    });
                }
            }, options.delay);
        }
    } else {
        addMembers(etext);
        bindEvents();
    }
}
Brigand
  • 84,529
  • 20
  • 165
  • 173
  • Thanks for the answer man, just about to test. just wondering how to set the json_url_list? something lile [url1,url2,url3] ? – ComeRun Mar 22 '13 at 02:14
  • Yeah. Like I said, it might need some tweaking, but I don't have any data to test it on. – Brigand Mar 22 '13 at 02:37
  • first try was not successful, what is all_data by the way? – ComeRun Mar 22 '13 at 03:43
  • Please edit this answer with the code that works for you. all_data was something I was going to use, but I found a cleaner way to write it. – Brigand Mar 22 '13 at 05:08