Tuesday, June 18, 2013

Load JSON Files Synchronously with jQuery

In jQuery, the getJSON operator can load any JSON file, however this operation is done asynchronously. Meaning that, in cases where you need to wait until your data file is loaded, using getJSON method is useless. Here is one way you can achieve your goal of loading JSON files synchronously:

function loadJsonFileSynch()
{
        $.ajax({
            url: 'path/to/json/file.json',
            async: false,
            dataType: 'json',
            success: function (response) {
                $.each(response, function(key, val) {
                    // Do processing here
                });
            }
        });
}

17 comments:

  1. This is deprecated now and will produce a warning
    Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.



















    ReplyDelete
  2. A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.
    Python Online training
    python Training in Chennai
    Python training in Bangalore

    ReplyDelete
  3. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Selenium training in Chennai
    Selenium training in Bangalore
    Selenium training in Pune
    Selenium Online training

    ReplyDelete
  4. Such a great information for blogger i am a professional blogger thanks…

    Softgen Infotech is the Best Oracle Training institute located in BTM Layout, Bangalore providing quality training with Realtime Trainers and 100% Job Assistance.

    ReplyDelete
  5. Truly, this article is really one of the very best in the history of articles. I am a antique ’Article’ collector and I sometimes read some new articles if I find them interesting. And I found this one pretty fascinating and it should go into my collection. Very good work!
    Data analytics courses
    data science interview questions

    ReplyDelete
  6. I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work.
    ai training in bangalore
    Machine Learning Training in Bangalore

    ReplyDelete
  7. It’s good to check this kind of website. I think I would so much from you. ExcelR Machine Learning Courses In Pune

    ReplyDelete
  8. You have clarified the idea truly well. Was searching for this data from some time and fortunately I discovered your post. Searching forward for a greater amount of such useful updates from you
    Data Science Training In Hyderabad
    Data Science Course In Hyderabad

    ReplyDelete
  9. I genuinely appreciated understanding it. Sitting tight for some more incredible articles like this from you in the nearing days.

    Python Training In Pune
    python training institute in pune

    ReplyDelete
  10. This concept is a good way to enhance knowledge. thanks for sharing.
    Data Science
    Selenium
    ETL Testing
    AWS
    Python Online Classes

    ReplyDelete
  11. I recently came across your article and have been reading along. I want to express my admiration of your writing skill and ability to make readers read from the beginning to the end. I would like to read newer posts and to share my thoughts with you.
    data science course in hyderabad with placements

    ReplyDelete
  12. AI Patasala aims at providing the most effective Python Training in Hyderabad. Our school has taught a lot of individuals and assisted them in locating good jobs.
    Python Course in Hyderabad

    ReplyDelete

  13. Infycle Technologies, the No.1 Cloud training center offers attractive AWS Training in Chennai with the remunerative DevOps Course for the candidate. Along with the courses, 100% placement training guidance will also be given for the welfare of your career. For more, reach us by calling 7502633633, 7502633633.

    ReplyDelete