0

I would like to take the results of my $.getJSON and place that JSON data, specifically the facility. FacilityName, as the values for the array availableTags. I have tried executing a function call where you see the // TODO: but I am not getting this sorted out. I'm sure it is easy for your jQuery experts! I DO see the facilities displayed on my page in the <div id="info"></div> tag as I would expect.

<script type="text/javascript">

$(function () {
    $('#datePicker').datepicker();
});

var names = [];

$.getJSON('FacilitiesAsync','sourceDb=myDb',processFacilities);
function processFacilities(data) {
    $.each(data, function (facilities, facility) {
        names += facility.FacilityName;
    }); // end of each

    alert(names);

    $("#tags").autocomplete("source", names);
};

$(function () {
    $("#tags").focusout(function () {
        $.ajax({
            beforeSend: function() {
                alert("Testing");
            },
            complete: function () {
                alert("Done!");
            }
        });
    });
});

</script>
2
  • Inside the getJSON callback: $("#tags").autocomplete({ source: somehowUsingTheJSONResponseData }); (I believe source can also be a function.) Commented Nov 19, 2013 at 4:28
  • stackoverflow.com/questions/31129/… Commented Nov 19, 2013 at 4:29

1 Answer 1

0

your TODO block contain inside of self invoking anonymous function, probably it executes before your getJSON executes, so in time of TODO block executing there is no json data. try to access data after getJSON function, may be in callback or within done of the getJSON.

Sign up to request clarification or add additional context in comments.

8 Comments

Yes, I agree. HOW do I call the callback function to load the data for the autocomplete? So the page loads and this JSON data is returned in the background with an ajax call. Once I have all the data it will be available in the autocomplete input control
Something happened to the post made by another user that was helping me
I get the results I always had. I want to see them in the autocomplete. That is still not working.
Are you using jQuery UI for autocomplete?
But you didn't mention that in your question, that's why I ask, hence refer link it seems your autocomplete have syntax error. And try with raw data for check whether it works
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.