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

时间:2023-01-14 08:58:29

i want to get xml data from remote domain (multiple xml files) i am trying to get my xml using php proxy code and returning the result to ajax callback function to be parsed. my code is :

我想从远程域(多个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>

and my php proxy is:

我的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);
}
?>

i get my data easily for one link but i want to make that link ($daurl) to change depending on ajax parameter. my problem is that i cant get any ajax parameter from php proxy page i tried GET, POST but it just does not work it always seems that $_POST and $_GET arrays are empty and do not hold my ajax parameters can anybody help me , please?

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

1 个解决方案

#1


0  

Use data : {country : 'england'} instead of parameters : {country : 'england'} like this:

使用数据:{country:'england'}而不是参数:{country:'england'},如下所示:

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

#1


0  

Use data : {country : 'england'} instead of parameters : {country : 'england'} like this:

使用数据:{country:'england'}而不是参数:{country:'england'},如下所示:

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