Ajax返回PHP文本而不是解析代码

时间:2019-06-16 05:53:50

标签: php ajax xmlhttprequest apache2.4

本地环境是:  Apache / 2.4.34(Unix)PHP / 7.1.23 所有conf。文件已被检查并重新检查,并添加了额外的cmd,例如:


        <IfModule>
       # PHP 7 specific configuration
       ....
       </IfModule>
        phpinfo() works fine etc.

xmlhttp代码为:

var xmlhttp = new XMLHttpRequest();

          xmlhttp.open("GET", "php/getARCHIVE.php");
          xmlhttp.setRequestHeader('Access-Control-Allow-Origin','localhost');
          xmlhttp.send();

          xmlhttp.onreadystatechange = function() {
            if (this.readyState === 4 && this.status === 200) {
              console.log(this.responseText);
            } else {
             console.log("Loading...");
            };
          }
            }

并返回: 正在加载...

    <?php
    echo 'hi everyone!';
    ?> 

为文本!

或......

    $.ajax( {
        url: 'php/getArchive.php',
            crossDomain: true,
        error:      function( jqXHR, statusMessage, errorThrown){console.log('serverRequest for php:' + "\n" + statusMessage + "\n" + errorThrown);},
        success:    function( response, status, jqXHR ){
            callback(response);
        }
    });
    }

...返回相同的文本:

   serverRequest for php:
    parsererror
    Error: Invalid XML: <?php
    echo 'hi everyone!';
    ?>

伴随的注释/错误是: “ XML解析错误:找不到根元素”

所以我如何让服务器识别.php文件-仅仅是:

     <?php echo 'hi everyone!'; ?>

i.e. the text that is being returned

0 个答案:

没有答案