0

i have an ajax call. Php page (A) called by ajax requires some other php page (B). Page "B" is php file looking something like this

<html>
<head> javascript code </head>
<body> PHP Code </body>

Inside of "head" tags is javascript code. Now, Page "A" includes page "B", but instead of expected result, it echoes pure javascript code from included page "B"!

How to prevent that?

2
  • 2
    Can you show us the code being used? Commented Jan 7, 2011 at 16:32
  • Ajax code, php code, or that javascript code? Commented Jan 7, 2011 at 16:38

3 Answers 3

1

Take out the eval() function, so your code will look like this:

pausecontent = pausecontent.concat(ajax.responseText);

`

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

2 Comments

This should be a comment and not an answer.
fair point, i'm new to stackoverflow, although i will edit so it becomes an answer now.
0

When you include a file in php, if the include file contains php it's processed, else the file's content will automatically be sent to the output which means the page content will be sent and viewed by the user's browser. to prevent that, you have to methods :

  1. Put the HTML into a variable
  2. Use file_get_content to get the entire file content then send it by ajax

Best Regards NiL

Comments

0

Here is ajax code:

if (window.XMLHttpRequest)
        ajax=new XMLHttpRequest();
    else
        ajax=new ActiveXObject("Microsoft.XMLHTTP");

    ajax.onreadystatechange = function()
    {
        if(ajax.readyState==4 && ajax.status==200)
            {
                pausecontent = pausecontent.concat(eval(ajax.responseText));
            }
    }

    ajax.open("GET", "../universal/uzmi-feed-za-skrol.php?jez="+jez, true);
    ajax.send(null);

javascript code is needed in file B because some elements are generated from php, and have to have "onclick" handlers....I know, it's not so good structure, but it could be very painfully to reconstruct all that :\

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.