ajax echo返回javascript代码!

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?

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

pausecontent = pausecontent.concat(ajax.responseText);

`

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

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 :\