Javascript jQuery中未解析XML
当我尝试使用插件解析我的代码时,它没有做它应该做的事情——循环遍历下面的模板,并在Javascript jQuery中未解析XML,javascript,php,jquery,xml,Javascript,Php,Jquery,Xml,当我尝试使用插件解析我的代码时,它没有做它应该做的事情——循环遍历下面的模板,并在位置输出XML标记。相反,它只返回模板的一个实例,没有任何内容代替 Chrome JavaScript控制台中不返回任何内容 奇怪的是,我有一个很好用的 下面是我使用的jQuery: $('.feed').feeds({ feeds: { feed1: 'http://www.comfyshoulderrest.com/scrape.php?id=1' // this one doesn't
位置输出XML
标记。相反,它只返回模板的一个实例,没有任何内容代替
Chrome JavaScript控制台中不返回任何内容
奇怪的是,我有一个很好用的
下面是我使用的jQuery:
$('.feed').feeds({
feeds: {
feed1: 'http://www.comfyshoulderrest.com/scrape.php?id=1' // this one doesn't work
},
//max: 3,
loadingTemplate: '<h1 class="feeds-loader">Loading items...</h1>',
entryTemplate: '<div class="item"><a href="http://google.com"><div class="image"><img src="images/tie.jpg" style="width: 100%;"></div></a>' +
'<div class="text"><ul class="list-inline">' +
'<li><span class="price text-warning"><strong>£7.00</strong></span> <span class="text-muted"><strike>£14.00</strike></span></li>' +
'<li class="text-muted"><strong>Topman</strong></li></ul>' +
'<!=title!>' +
'</div></div>'
});
$('.feed').feed({
提要:{
feed1:'http://www.comfyshoulderrest.com/scrape.php?id=1“//这个不行
},
//最高:3,
loadingTemplate:“正在加载项…”,
入口模板:“”+
“”+
“- £;7.00£;14.00
”+
“- Topman
”+
'' +
''
});
以下是生成XML文件的代码:
<?php
function scrape($list_url, $shop_name, $photo_location, $photo_url_root, $product_location, $product_url_root, $was_price_location, $now_price_location, $gender, $country) {
header("Content-Type: application/xml; charset=UTF-8");
$xml = new SimpleXMLElement('<rss/>');
$xml->addAttribute("version", "2.0");
$channel = $xml->addChild("channel");
$channel->addChild("product_url", $product_url);
$channel->addChild("shop_name", $shop_name);
$channel->addChild("photo_url", $photo_url);
$channel->addChild("was_price", $was_price);
$channel->addChild("now_price", $now_price);
$html = file_get_contents($list_url);
$doc = new DOMDocument();
libxml_use_internal_errors(TRUE);
if(!empty($html)) {
$doc->loadHTML($html);
libxml_clear_errors(); // remove errors for yucky html
$xpath = new DOMXPath($doc);
/* FIND LINK TO PRODUCT PAGE */
$products = array();
$row = $xpath->query($product_location);
/* Create an array containing products */
if ($row->length > 0)
{
foreach ($row as $location)
{
$product_urls[] = $product_url_root . $location->getAttribute('href');
}
}
$imgs = $xpath->query($photo_location);
/* Create an array containing the image links */
if ($imgs->length > 0)
{
foreach ($imgs as $img)
{
$photo_url[] = $photo_url_root . $img->getAttribute('src');
}
}
$result = array();
/* Create an associative array containing all the above values */
foreach ($product_urls as $i => $product_url)
{
$result = array(
'product_url' => $product_url,
'shop_name' => $shop_name,
'photo_url' => $photo_url[$i]
);
$item = $channel->addChild("item");
$item->addChild("product_url", $result['product_url']);
$item->addChild("shop_name", $result['shop_name']);
$item->addChild("photo_url", $result['photo_url']);
}
//print_r($result);
}
else
{
echo "this is empty";
}
echo $xml->asXML();
}
/* CONNECT TO DATABASE */
$dbhost = "xxx";
$dbname = "xxx";
$dbuser = "xxx";
$dbpass = "xxx";
$con = mysqli_connect("$dbhost", "$dbuser", "$dbpass", "$dbname");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$id = $_GET['id'];
/* GET FIELDS FROM DATABASE */
$result = mysqli_query($con, "SELECT * FROM scrape WHERE id = '$id'");
while($row = mysqli_fetch_array($result)) {
$list_url = $row['list_url'];
$shop_name = $row['shop_name'];
$photo_location = $row['photo_location'];
$photo_url_root = $row['photo_url_root'];
$product_location = $row['product_location'];
$product_url_root = $row['product_url_root'];
$was_price_location - $row['was_price_location'];
$now_price_location - $row['now_price_location'];
$gender = $row['gender'];
$country = $row['country'];
scrape($list_url, $shop_name, $photo_location, $photo_url_root, $product_location, $product_url_root, $was_price_location, $now_price_location, $gender, $country);
}
mysqli_close($con);
?>
那么基本上你是说你下载了一个免费的插件,但它不能正常工作?我是说我在试图找出两个相似文件之间的区别,其中一个可以与插件一起工作,另一个不能。所以问题更多的是关于XML文件,而不是插件。