Ajax call after page load

compsci45000

I am trying to build a search page where the user inputs text into a search box and the page is generated based on the search. I am having timing issues because the blank search page is loading after the JS tries to edit the values on the page.

$.ajax({
    type: 'GET',
    url: '/index.php/content/generate_search',
    data: {
        search: input.val()
    },
    beforeSend: function() {
        window.location.href = '/index.php/content/search';
    },
    success: function() {
        $('.hero h1').text(input.val());
    }
});
Victor

To check that the DOM is completely loaded, many steps have to be done taking all the browsers into consideration. (I cannot find the implementation in the jQuery source, but I will come back with a link).

The easiest and probably best way of doing it, since you're already using jQuery is by:

$( function() {
    // your code here
} );

which is a shorthand for

$( document ).ready( function() {
    // your code here
} );

EDIT

Ok, so as I promised, I came back with the implementation of document.ready. You can find it here, on GitHub. Here is a permanent link to the current version of the file.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to stop refreshing page after ajax call?

From Dev

Load directive after AJAX call

From Dev

Rails 4 page reload after ajax call

From Dev

After ajax call when i click something page jump to top

From Dev

Call Javascript function after AJAX load

From Dev

Stop Wicket from repainting the whole page after each ajax call

From Dev

HTML5 Video to play after AJAX page load

From Dev

Make Ajax call after page load

From Dev

Is it possible to call a function after Page_Load event?

From Dev

call function after complete page load

From Dev

facebook page plugin doesn't work after ajax page load

From Dev

Ajax call does not load the page but goes into .fail?

From Dev

Why page reloads after JQuery ajax call?

From Dev

How to prevent page reloading after ajax call jquery

From Dev

Call function after delay on page load using Angular

From Dev

JQuery Click Handlers not Working After Ajax Page Load

From Dev

Ajax call before page load

From Dev

no csrf token after ajax page load

From Dev

Jquery ajax call works only on first page load

From Dev

Is it possible to redirect the page with PHP after an Ajax call?

From Dev

Call function after AJAX load

From Dev

Fire JQuery AJAX call after Kendo UI AJAX page load

From Dev

Render table values dynamically using Ajax after page load in php

From Dev

$.ajax json GET reverts all jquery after page load

From Dev

Ajax not being called the first time right after page load

From Dev

run a ajax call result on load and after 5 seconds

From Dev

Load ajax after page load

From Dev

jquery .load() after page call function

From Dev

Ajax call after redirect page

Related Related

HotTag

Archive