Click here to Skip to main content
15,900,108 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
my pages hangs when it reaches to execute the code of ajax({}). there comes a loader then it stucks

What I have tried:

i tried to link ajax external links
Posted
Updated 30-Sep-17 6:19am

1 solution

You just need the jQuery library for your Ajax to work. Other libraries, if you include them, might hang the page because they may not be async or they might require other parameters to be async in nature.
Quote:
my pages hangs when it reaches to execute the code of ajax({}).
The "A" in Ajax stands for asynchronous. Which means, that the code must execute asynchronously and should avoid holding on to the main thread which makes the page responsive. I have a few of my own pages, running on my website and they are responsive.
JavaScript
$(document).ready(function () {
    // Assume you want to send Ajax requests on button click, whose id is btn
    $("#btn").click(function() {
        $.ajax({
            url: 'your/path',
            data: { query: string },
            success: function (data) {
              // Done
            }
        });
    });
});

Try this code in your pages for once. This must never hang your page. The pure jQuery solution for Ajax is asynchronous and does nothing to hang, if your page does get hung, you need to check what other libraries are you trying to load and whether there are some logging or analytics suite that are trying to hang your page.

jQuery.ajax() | jQuery API Documentation[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900