Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current URL from document.ready

I am trying to parse my URL in document.ready() so that I can get the id of the current page and dynamically populate the page with results from an AJAX call. The problem I am running into is due to the fact that I think that 'document.URL' references the previous page until 'document.ready()' has fully executed.

How do I get around this? I have researched document.load(), and auto-refreshing the page once, but I cannot seem to get this to work. I have been working on this since yesterday.

Here is my code:

$( document ).ready( function(){
    var id = document.URL.substring(document.URL.lastIndexOf('?')+4);
    if(!loadObject.executed) {
        loadObject(id);
        loadObject.executed = true;
    } else {
    $('#page-full').on('pagecreate', loadObject(id));
    }
});
like image 384
mmelear Avatar asked Mar 04 '14 19:03

mmelear


1 Answers

Try to use document.location.href instead of document.URL.

Hope this helps.

like image 102
nils Avatar answered Nov 01 '22 20:11

nils