我想从远程域(多个 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);
}
?>
我很容易为一个链接获取数据,但我想让该链接($daurl)根据 ajax 参数进行更改。我的问题是我无法从 php 代理页面获取任何 ajax 参数我尝试了 GET、POST 但它只是不起作用它似乎总是 $_POST 和 $_GET 数组是空的并且不保存我的 ajax 参数有人可以帮助我吗? ?