Skip to content Skip to sidebar Skip to footer

Php Include/require Method With Variable Path

Someone to help where I'm wrong! Ajax returns correct information. It also shows on 'success' include page with all data in 'alert(html)'. Echo $idName; and echo $path; print corre

Solution 1:

Since no one with sufficient knowledge, wants to spend time on solving this problem, and I am sure that is easily solvable, I solved for now and post hoping to find useful for other beginners in this area as me! I went back to the first approach. This way is much simpler and provides few following steps: page1 achor click>page1 js var for path and asign to intermediate filed in page1>js load page3 in page2 with filePath. The problem with premature refreshing fixed as follows: first with splitting JS file where were all the codes for those three files, in three for each page separately, also adding setTimeout function to the other procedures for executing with correct order. Now it’s running smoothly!

main-page.php
<navclass=”side-menu”><?php ... Creating a side-menu from database MySQL ... ?>
// echo resault:
<ul><liclass=”sub-menu”><aid=”forms-byclass1-subdir”href=”#”></a><ul><liclass=”anchor”><ahref=”#form-some-name”><spanid=”form-header”>form-label</span></a></li></ul></li></ul></nav></nav><divid="fc"><?phprequire("form-carrier.php"); ?></div><divid=”hidden”
    <inputtype="text"id="path"name="path"value=”” /></div>
…
form-carrier.php
…
<divid="include"></div> 
…
Main-page.js
…
$(".sub-menu > a").click(function(e){
    e.preventDefault();
    … variables to get a desired path …
    $("#include").load(path);
    setTimeout(function() {
        … other procedures …
    }, 60);
});

This does not mean that I was gave up from approach, using Ajax, PHP and db, but until I find the way to fix it, this is certainly a good solution. Therefore remains the call for contribution from the gurus of web-design.

Note for proper functioning various events: because the file is dynamically included , will be problematic using of JQuery .click (), as well as JavaScript HTML DOM EventListener if it not used in html inline. The most reliable way, at least in my case, is using of Jquery “.on( events [, selector ] [, data ], handler )”.

Post a Comment for "Php Include/require Method With Variable Path"