亲爱的先生们, 我正在加载一个包含1000多条记录的xml文件,其方案是:
<?xml version="1.0" encoding="UTF-8"?>
<deals>
<deal>
<deal_id>1</deal_id>
<deal_title> <![CDATA[THE TITLE]]> </deal_title>
<deal_description> <![CDATA[THE DESCRIPTION]]> </deal_description>
<deal_url> <![CDATA[http://www.thedomain.com]]> </deal_url>
<deal_price>12.00</deal_price>
<deal_previous_price>68.00</deal_previous_price>
<deal_discount>82</deal_discount>
<deal_image> <![CDATA[http://www.thedomain.com/images/image.jpg]]> </deal_image>
<deal_shop>DEAL SITE NAME</deal_shop>
</deal>
</deals>
不幸的是有人为我提供了这个xml并且没有订购。 现在我使用下面的代码在我的php文件中加载我的xml来自xml的4条记录:
<ol class="timeline" id="updates">
<?php
$url = "http://www.somedomain.com/xml.xml";
$xml = simplexml_load_file($url);
$bar_count = $xml->deal->count();
$limit = 0;
$num = 4;
foreach($xml->deal as $deal)
{
if($limit == $num)
break;
echo'
<li>
<div class="dealmasterblock" id="'.$num.'">
<div class="dealsite">'.$deal->deal_shop.'</div>
<div class="dealsimageblock">
<div class="pricebg">
<div style="width:55px; height:26px; float:left; margin-left:8px; margin-top:14px; font-family:Verdana, Geneva, sans-serif; color:#333; font-size:18px;">-'.$deal->deal_discount.'%</div>
</div>
<div class="dealsimg"><img src="'.$deal->deal_image.'" width="284" height="199" border="0" /></div></div>
<div class="others">
<div class="dealtitle">'.$deal->deal_title.'</div>
</div>
<div class="moreoptions">
<div style="width:465px; height:34px; float:left; margin-top:3px;">
<div style="width:180px; height:28px; padding-top:6px; float:left; font-family:Verdana, Geneva, sans-serif; background-color:#3189EE; color:#FFF; text-align:center; border-right:1px solid #0CF; margin-right:10px;">Αρχική τιμή: '.$deal->deal_previous_price.'€</div>
<div style="width:180px; height:28px; padding-top:6px; float:left; font-family:Verdana, Geneva, sans-serif; background-color:#3189EE; color:#FFF; text-align:center; border-right:1px solid #0CF;">Μόνο: '.$deal->deal_price.'€</div>
</div>
<div style="width:147px; height:40px; float:right;"><a href="'.$deal->deal_url.'" target="_blank"><img src="images/morebtn.png" width="147" height="40" border="0" /></a></div>
</div>
</div>
</li>';
$limit++;
}
?>
</ol>
<div style="clear:both;"></div>
<div id="more<?php echo $num; ?>" class="morebox">
<a href="#" class="more" id="<?php echo $num; ?>">περισσότερα...</a>
</div>
<div style="clear:both;"></div>
</div>
我已经将一个jquery / ajax代码附加到了更多类的按钮,所以当我按下它时会加载更多记录。 jquery代码是:
<script type="text/javascript">
$(document).ready(function(){
$('.more').on('click', function(evt){
var ID = $(this).attr("id");
if(ID)
{
$("#more"+ID).html('<img src="images/moreajax.gif" />');
$.ajax({
type: "POST",
url: "moredeals.php",
data: "lastmsg="+ ID,
cache: false,
success: function(html){
$("ol#updates").append(html);
$("#more"+ID).remove();
//$('ol#updates').fadeIn("slow");
//alert('Return ok');
//$("#more"+ID).html('<img src="images/moreajax.gif" />');
}
});
}
else
{
$(".morebox").html('The End');
}
return false;
});
});
</script>
Moredeals.php是加载更多交易的ajax文件是:
<?php
$url = "http://www.somedomain.com/xml.xml";
$xml = simplexml_load_file($url);
if(isSet($_POST['lastmsg']))
{
$lastmsg=$_POST['lastmsg'];
$url = "http://www.clickbanner.gr/xml/?xml_type=deals&affiliate_ID=16022";
$xml = simplexml_load_file($url);
$bar_count = $xml->deal->count();
$limit = 0;
$num = 8;
foreach($xml->deal as $deal)
{
if($limit == $num)
break;
echo'
<li>
<div class="dealmasterblock" id="'.$num.'">
<div class="dealsite">'.$deal->deal_shop.'</div>
<div class="dealsimageblock">
<div class="pricebg">
<div style="width:55px; height:26px; float:left; margin-left:8px; margin-top:14px; font-family:Verdana, Geneva, sans-serif; color:#333; font-size:18px;">-'.$deal->deal_discount.'%</div>
</div>
<div class="dealsimg"><img src="'.$deal->deal_image.'" width="284" height="199" border="0" /></div></div>
<div class="others">
<div class="dealtitle">'.$deal->deal_title.'</div>
</div>
<div class="moreoptions">
<div style="width:465px; height:34px; float:left; margin-top:3px;">
<div style="width:180px; height:28px; padding-top:6px; float:left; font-family:Verdana, Geneva, sans-serif; background-color:#3189EE; color:#FFF; text-align:center; border-right:1px solid #0CF; margin-right:10px;">Αρχική τιμή: '.$deal->deal_previous_price.'€</div>
<div style="width:180px; height:28px; padding-top:6px; float:left; font-family:Verdana, Geneva, sans-serif; background-color:#3189EE; color:#FFF; text-align:center; border-right:1px solid #0CF;">Μόνο: '.$deal->deal_price.'€</div>
</div>
<div style="width:147px; height:40px; float:right;"><a href="'.$deal->deal_url.'" target="_blank"><img src="images/morebtn.png" width="147" height="40" border="0" /></a></div>
</div>
</div>
</li>';
$limit++;
}
?>
<div style="clear:both;"></div>
<div id="more<?php echo $num; ?>" class="morebox">
<a href="#" class="more" id="<?php echo $num; ?>">περισσότερα...</a>
</div>
<?php
}
?>
<script type="text/javascript">
$(document).ready(function(){
$('.more').on('click', function(evt){
var ID = $(this).attr("id");
if(ID)
{
$("#more"+ID).html('<img src="images/moreajax.gif" />');
$.ajax({
type: "POST",
url: "moredeals.php",
data: "lastmsg="+ ID,
cache: false,
success: function(html){
$("ol#updates").append(html);
$("#more"+ID).remove();
}
});
}
else
{
$(".morebox").html('The End');
}
return false;
});
});
</script>
现在的问题是,当按下更多按钮时,我可以加载更多8个交易,但与4个第一个记录相同。
有什么建议吗?