dcsimg
www.webdeveloper.com
Results 1 to 8 of 8

Thread: Load page from other directory

  1. #1
    Join Date
    Aug 2017
    Posts
    13

    Load page from other directory

    I have a piece of javascript that loads a page in a certain div

    Code:
    $(document).on("click",".item2", function(e) {
    var filename = $(this).text().toLowerCase() + 'av' + '.php';
    
    filename = filename.replace(/\s+|'/g, '');
    
    
    $('#uitkomst2').load(filename);
    e.preventDefault();
    
    });
    Now I'd like load pages from another directory in a div, how can I do this?

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,395
    Please note that JQuery isn't JavaScript ..!

    So moved to JavaScript Frameworks
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  3. #3
    Join Date
    Dec 2012
    Posts
    1,542
    If that directory is a child of the current one:
    Code:
    filename = "the-directory/" + filename.replace(/\s+|'/g, '');
    If it is a sibling of the current one:
    Code:
    filename = "../the-directory/" + filename.replace(/\s+|'/g, '');

  4. #4
    Join Date
    Aug 2017
    Posts
    13
    I found a problem here, I have a file called statutenav.php en one called statuten.php in the same directory, and when I click statuten it takes statutenav.php.
    So far everything ok ( 'statuten' + 'av' + '.php' = statutenav.php

    Code:
    var filename = $(this).text().toLowerCase() + 'av' + '.php';
    When I try to reach statuten.php in a directory called av like this,


    Code:
    var filename = 'av/' $(this).text().toLowerCase()  + '.php';
    I get statuten from directory av.

    But when I do this

    Code:
    var filename = 'av/' $(this).text().toLowerCase()+ 'av'  + '.php';
    I got nothing and there's a file statutenav.php in the av directory.

    Any idea what is missing here?

  5. #5
    Join Date
    Aug 2017
    Posts
    13
    There should be a + between 'av/' and $(this) but same problem.

  6. #6
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,395
    You have a typo
    Code:
    var filename = 'av/' $(this).text().toLowerCase()  + '.php';
    is not the same as
    Code:
    var filename = 'av/' + $(this).text().toLowerCase()  + '.php';
    It often pays to open the console and read what errors you are getting, F12 opens and closes the console, click on log, see the errors listed, tells you waht line you need to look at and what it found wrong.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  7. #7
    Join Date
    Aug 2017
    Posts
    13
    Problem solved it was a error in the my db.php.

    I made some changes but forgot some pages

    Thanks for the help.

  8. #8
    Join Date
    Jul 2014
    Location
    CA
    Posts
    78
    You have to import that page from other directory into your main page. Than you can use their functions.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center