AJAX GET返回的PHP脚本 [英] AJAX GET returns the php script

查看:136
本文介绍了AJAX GET返回的PHP脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回结果,整个PHP脚本一个非常简单的Hello World Ajax的PHP的例子。这里的code:

I have a very simple hello world ajax-php example that returns as a result the whole php script. here's the code:

   $.ajax({
        type: "GET",
        contentType: "text",
        url: "hello-world.php",
        success: function(data){
            $("#myDiv").text(data);
            console.log(data);
        }

    });


服务器code:

<?php
// A simple web site in Cloud9 that runs through Apache
// Press the 'Run' button on the top to start the web server,
// then click the URL that is emitted to the Output tab of the console

echo 'Hello world!';

?>


这里的控制台日志:

<?php
// A simple web site in Cloud9 that runs through Apache
// Press the 'Run' button on the top to start the web server,
// then click the URL that is emitted to the Output tab of the console

echo 'Hello world!';

?> 

谢谢!

推荐答案

那么你的PHP是不是跨preTED,因而被返回原始的HTML。

Chances are your PHP isn't being interpreted, and thus is being returned as raw HTML.

检查<一href="http://stackoverflow.com/questions/10186009/ajax-responsetext-returns-my-entire-php-$c$c-locally">here对于类似的问题。

这篇关于AJAX GET返回的PHP脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆