我可以从php代理页面获取ajax参数吗?

时间:2013-01-26 09:23:53

标签: php xml ajax

我想从远程域(多个xml文件)获取xml数据我试图使用php代理代码获取我的xml并将结果返回到要解析的ajax回调函数。 我的代码是:

<html>
<head>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
$.ajax({
    type: "POST",
    url: 'proxy.php',
    parameters : {country : 'england'},
    dataType: "xml",
    success: parseXml
 });

function parseXml(xml) {
    console.log(xml);
    $(xml).find("category").each(function() {
        var name = $(this).attr('name');
        var file_group = $(this).attr('file_group');
        $("#live").append('<ul class="contests"><li class="contest_name"><table class="title_table" border="0"><tr><td><input type="checkbox" class="checkbox"></td><td class="name"><h3>'+ name +'</h3></td><td class="contest_image"><a href="#"><img src="./include-images/standing.png"></img></a></td></tr></table></li></ul>');
        $(this).find("match").each(function() {
        var time = $(this).attr('time');
        var status = $(this).attr('status');
        var ht_score = $(this).find('ht').attr('score');
        var localteam = $(this).find('localteam').attr('name');
        var visitorteam = $(this).find('visitorteam').attr('name');
        var goals_localteam = $(this).find('localteam').attr('goals');
        var goals_visitorteam = $(this).find('visitorteam').attr('goals');
        $("#live").append('<ul class="contests"><li class="fixture"><table class="fixture_table" border="0"><tr><td><input type="checkbox" class="checkbox"></td><td class="status">'+ status +'</td><td class="localteam">'+ localteam +'</td><td class="goals_localteam">'+ goals_localteam +'</td><td class="space">-</td><td class="goals_visitorteam">'+ goals_visitorteam +'</td><td class="visitorteam">'+ visitorteam +'</td><td class="ht_score">'+ ht_score +'</td></tr></table></li></ul>');
    });
    });
}


</script>
</head>
<body>

<div id='live'></div>
</body>
</html>

我的php代理是:

<?php
// Set your return content type
header('Content-type: application/xml');

// Website url to open

$daurl = 'http://www.example.com/getfeed/b4998d59890f4280827e3b126a628af0/soccernew/home';

// Get that website's content
$handle = fopen($daurl, "r");

// If there is something, read and return
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        echo $buffer;
    }
    fclose($handle);
}
?>

我可以轻松获取一个链接的数据,但我想根据ajax参数进行更改($ daurl)。我的问题是,我不能从PHP代理页面获取任何ajax参数我尝试GET,POST但它只是不起作用它似乎总是$ _POST和$ _GET数组是空的并且不持有我的ajax参数可以任何人帮助我,请?

1 个答案:

答案 0 :(得分:0)

使用data : {country : 'england'}代替parameters : {country : 'england'},如下所示:

$.ajax({
    type: "POST",
    url: 'proxy.php',
    data: {country : 'england'},
    dataType: "xml",
    success: parseXml
 });