如何使用ajax插入iFrame/PHP?
我正在尝试包含一个类似Facebook的按钮iFrame,其中包含PHP:如何使用ajax插入iFrame/PHP?,php,javascript,jquery,ajax,facebook,Php,Javascript,Jquery,Ajax,Facebook,我正在尝试包含一个类似Facebook的按钮iFrame,其中包含PHP: <iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo $row['id']; ?>&send=false&layout=button_count" style="border: medium none; overflow: hidden; width: 115px; height: 21px;" al
<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo $row['id']; ?>&send=false&layout=button_count" style="border: medium none; overflow: hidden; width: 115px; height: 21px;" allowtransparency="true" frameborder="0" scrolling="no"></iframe>
直播版。单击“获取更多”。将显示引号,但没有类似按钮
在构建
成功函数时,您没有添加iframe标记
您所做的只是添加(每行):
这当然是为了说明原理,而不一定是您需要编写的确切代码。您需要添加其他功能(如隐藏前面的引号等)在实时示例中,您不需要添加iframe标记。如果添加了你,它会正常工作。是的,当页面加载时,我添加了。但当点击“获取更多报价”时,它不会出现。当我插入iframe或尝试使用iframe时,ajax崩溃了。你真的需要使用iframe吗?如果您对FBML没意见(希望您能),您可以检查这个问题,我的意思是,在当前代码中,当用户单击按钮(getQuotes)时运行的函数不会添加iframe标记。你确定你没有忘记某个内容吗?我尝试将其添加到getQuotes,但失败。
getQuotes
隐藏当前的li
,并将新的添加到列表中。我想你看到的是那些刚刚被隐藏的内容。@MarceloDiniz tnx为了引起你的注意,将我的答案更改为Fit。我是否将其添加到quotes.php中?这取决于你,你可以将其添加到quotes.php
中,或者创建一个新文件并更改$.ajax
调用中的url
参数
<ul class="recent-list">
<?php
require("inc/connect.php");
$result = mysql_query("SELECT * FROM entries ORDER BY id DESC LIMIT 0, 20", $link);
while($row = mysql_fetch_array($result)){ ?>
<li id="qoute-<?php echo $row['id']; ?>" class="quote-wrap group">
<span>
<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo $row['id']; ?>&send=false&layout=button_count" style="border: medium none; overflow: hidden; width: 115px; height: 21px;" allowtransparency="true" frameborder="0" scrolling="no"></iframe>
</span>
<div class="quote">
<p>
<?php echo htmlentities($row['quote']); ?>
</p>
</div><!-- /.quote -->
</li>
<?php } ?>
</ul>
function getQuotes(start, limit) {
//Clear the recent list element
//$(".recent-list").html("");
var recent = $(".recent-list");
$(".recent-list li").animate({opacity: 0.1} , 800).hide(500);
$.ajax({
url: "quotes.php?start=" + start + "&limit=" + limit,
success: function (data) {
data = jQuery.parseJSON(data)
console.log("success");
//Data should now be a javascript array of objects.
for (i = 0; i < data.length; i++) {
var newElem = jQuery("<li></li>").attr('id', data[i].id).addClass('quote-wrap-group');
newElem.append("<div class='quote'><p>" + data[i].quote + "</p></div>");
$(".recent-list").append(newElem);
}
}
});
}
var currentIndex = 0;
$("#more").click(function () {
getQuotes(currentIndex, 20);
currentIndex += 10;
});
$start = $_GET['start'];
$limit = $_GET['limit'];
$sql = "SELECT * FROM entries ORDER BY id DESC LIMIT ".$start.", ".$limit;
$result = mysql_query($sql, $link) or die("Error in query: ".mysql_error());
$data = array();
while($row = mysql_fetch_array($result)) {
array_push($data, $row);
}
echo(json_encode($data));
<li id="54" class="quote-wrap-group">
<div class="quote">
<p>fdggfdgdgdgfdg</p>
</div>
</li>
$data = getData();//Get the data from the database here;
foreach($data as $row):
?>
<li id="qoute-<?php echo $row["id"];?>" class="quote-wrap group">
<span>
<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo row["id"];?>&send=false&layout=button_count" style="border: medium none; overflow: hidden; width: 115px; height: 21px;" allowtransparency="true" frameborder="0" scrolling="no"></iframe>
</span>
<div class="quote"><p><?php echo $row["quote"];?></p></div>
</li>
<?php endforeach; ?>
function getQuotes(start, limit){
$.ajax({
url:"quotes.php?start=" + start + "&limit=" + limit,
dataType: "html",
success: function(response){
$("ul.recent-list").append(response);
}
});
}