简体   繁体   English

如何从JQuery调用PHP代理脚本

[英]How to call PHP proxy script from JQuery

I'm trying to get cross-domain Ajax to work. 我正在尝试使跨域Ajax工作。 I downloaded a PHP proxy script from the Yahoo Developer site, ran it from command line and verified that it receives the XML from the server with a GET request. 我从Yahoo Developer网站下载了一个PHP代理脚本,从命令行运行了它,并验证了它从服务器接收到带有GET请求的XML。

Now, I'm trying to connect to the PHP script within JS with no results. 现在,我试图连接到JS中的PHP脚本,但没有结果。 I have the following: 我有以下几点:

<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript">
$.ajax({
    type:"GET", 
    url:"proxy.php", 
    dataType:"html", 
    success:function(msg){
        alert(msg);
    }
});
</script>

What this does, though, is to output the source of the PHP script in the alert box, not the XML! 但是,这样做是在警告框中输出PHP脚本的源代码 ,而不是XML! Where am I going wrong? 我要去哪里错了?

Your server has to actually run php for this to work. 您的服务器必须实际运行php才能正常工作。 From your question, it sounds like it's just serving up proxy.php as a text file. 从您的问题来看,听起来好像只是将proxy.php作为文本文件提供服务。

You need to either use the server-side flavor of the proxy script that works for your platform, or also run/support php at the same time. 您需要使用适合您平台的代理脚本的服务器端风格,或者同时运行/支持php。 I'd recommend the former, running an equivalent proxy in whatever language/platform you're already running server-side. 我建议使用前者,以您已经在服务器端运行的任何语言/平台运行等效的代理。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM