1

リモートドメイン(複数の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);
}
?>

1つのリンクのデータを簡単に取得できますが、そのリンク($ daurl)をajaxパラメーターに応じて変更したいと思います。私の問題は、PHPプロキシページからajaxパラメータを取得できないことです。GET、POSTを試しましたが、動作しません。$_POSTおよび$_GET配列が空であり、ajaxパラメータを保持していないようです。 ?

4

1 に答える 1

0

data : {country : 'england'}このように代わりに使用してくださいparameters : {country : 'england'}

$.ajax({
    type: "POST",
    url: 'proxy.php',
    data: {country : 'england'},
    dataType: "xml",
    success: parseXml
 });
于 2013-01-26T10:50:35.150 に答える