将PHP代码插入我的page.xml

时间:2011-02-05 08:52:49

标签: php xml

page.xml.php不会显示任何输出,在firebug中我可以看到page.xml.php的get响应,我的类负责提取数据没有看到内容为xml数据

我怎样才能让它发挥作用?

的index.php

// Load config file
    $config = simplexml_load_file("resources/pinboard/config.xml.php");

page.xml.php

<?php header("Content-type: text/xml"); ?>
...
<module name="Weather" id="23">
    <title>Weather</title>
    <location><?php echo $_COOKIE['zip_code']; ?></location>
</module>
...

weather.php

...
protected $default_config = array(
                'title' => 'Weather',
                'refresh' => '200000', // Every 20 minutes
                'location' => "Los+Angeles",
                'format' => 'f'
);
...

site.js

...
$.ajax({
        type: "GET",
        url: "resources/pinboard/config.xml.php?" + new Date().getTime(),
        dataType: "xml",
        success: function(xml) {

            // Parse config
            $(xml).find('settings').children().each(function(test){
                settings[$(this)[0].localName] = $(this).text();
            });

            // Call init (startup the picboard)
            init();

        }
    });
...

1 个答案:

答案 0 :(得分:0)

您使用

加载xml.php文件
$config = simplexml_load_file("resources/pinboard/config.xml.php");

<击> 但这不会返回解析文件,只返回源。现在我不知道你的其他xml.php文件是否像这样加载,但你需要“通过网络服务器”才能使用它。

但是ajax调用似乎是正确的。

正如评论中所建议的那样:

  

使用更明智的应用程序结构