简体   繁体   中英

How to call PHP proxy script from JQuery

I'm trying to get cross-domain Ajax to work. 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.

Now, I'm trying to connect to the PHP script within JS with no results. 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! Where am I going wrong?

Your server has to actually run php for this to work. From your question, it sounds like it's just serving up proxy.php as a text file.

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. I'd recommend the former, running an equivalent proxy in whatever language/platform you're already running server-side.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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