开发者

Toggle php include with jQuery

On my php page I have two code includes that I use one at a time:

include_once "page1.inc.php";

or

include_once "page2.inc.php";

Can I include them with jQuery on click or do I need to include them b开发者_如何学Pythonoth, hide one, and then use toggle?


You could use load to load them as needed:

.load() sets the HTML contents of the matched element to the returned data. This means that most uses of the method can be quite simple:

$('#result').load('ajax/test.html');

So, when you first want to toggle one of them open, you could use load to pull over the data. You could bind the AJAX loading using one so that it would only be called once.


jQuery is for the frontend only. That said, there is no way that jQuery influences which page is included on the server side. Even if you hide the pagex.php using jQuery, it will still be visible when you view the source code.

If your pagex.php is only about views (no logic on them) then you could use jQuery to fetch them from the user browser, but not from the server.


include_once is PHP. That happens on the server side before it gets to the user. jQuery is client side. With jQuery, you can use AJAX to load in one of them or you can include both of them on the page and have jQuery toggle (hide/show) the div for whichever one needs to been shown or hidden.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜