0

I am working with some complex PHP intended for mobile , and it is using AJAX (as indicated by data-ajax="true" in <div>) to include other PHP files into the page and at the same time hiding the existing data using jQuery. While the header and address are changing, the actual web page is simply being updated. When updating for the first new "page" no javascript is added. The core page includes a PHP file involving output buffering, but I didn't think that would cause a scripting error. I'm using PHP 5.4.9, not sure if that will make a difference or not.

The core page (page1):

<?php
if (!isset($_SESSION)) session_start();

include_once("$path/lib/functions/show_header.php");

//PHP page including output buffer
show_header($html_back='normal', $html_home='public_page', $header_title='Directory', $bool_back=TRUE, $title=$header_title, $javascript=&$myScript, $cache=FALSE, $viewport=TRUE);
?>

<ul id="list" data-inset="true" data-role="listview" ><!--data-filter="true" data-filter-placeholder="Search for Feeds..."-->
<li id="header" data-role="list-divider">Select a Search Option</li>

<li>
    <a href="page2.php?header=Option1" data-ajax="true">Option 1</a>
</li>
<li>
    <a href="page2.php?header=Option2" data-ajax="true">Option 2</a>
</li>
<li>
    <a href="page2.php?header=Option3" data-ajax="true">Option 3</a>
</li>

</ul>
</div><!-- // Content-->
</div><!-- // Page-->
</body
</html>

The code getting inserted:

<script>alert("The JS is working!");</script>

<div data-role="page" data-theme="c">
    <div data-role="header" data-theme="b">
        <a href="#" data-rel="back" data-ajax="true" data-icon="arrow-l" data-direction="reverse">Back</a>
        <h1><?php echo $_GET['header']?></h1>
    </div>
    <div data-role="content" role="main">

        <textarea id=search name="search" cols="1" rows="1" onblur="return validate()" onfocus="this.innerHTML=''">Search For...</textarea>

        <ul id="list" data-inset="true" data-role="listview" >
            <li id="header" data-role="list-divider"></li>

            <li>
                <a id=button href="" data-ajax="true">Search</a>
            </li>

        </ul>
    </div><!-- // Content-->
</div><!-- // Page-->

Any assistance would be appreciated. I'm experienced with PHP, but a novice when it comes to AJAX and jQuery.

6
  • Can you share the jquery that you are using? Commented Mar 6, 2013 at 17:25
  • Unfortunately the jQuery is proprietary. However, by mistake I just found out the jQuery was parsing the php, but only things inside the outermost <div> on page2. Thank you for the quick response though. Commented Mar 6, 2013 at 17:28
  • 2
    Can you sum up your question in one sentence? Commented Mar 6, 2013 at 17:30
  • Not sure what the question is but with proper binding, you don't need any inline javascript. Commented Mar 6, 2013 at 17:30
  • Thats fine. Atleast can you explain your question and what you want to achive? What you get now? Commented Mar 6, 2013 at 17:32

1 Answer 1

0

The jQuery was grabbing only the PHP included in the outermost <div>. Somehow this never made it into the documentation. Documentation is king!

Once moving the javascript and php inside that <div> I could do anything I wanted. At that point I got rid of inline javascript and switched to javascript event handlers instead. I never was able to track down the exact jquery usage that caused it to ignore my php and javascript outside the <div>.

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.