1

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 both, hide one, and then use toggle?

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Load is great! I think this is what I was looking for. I just need to figure out how to load first page by default. Then on click I can hide it and load page2 and then on click of an element on page2, remove it and show() page1... I thin it should work.
1

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.