[英]jquery ajax to return HTML elements
Is it possible to return the entire data and innerhtml of a particular div or I have to follow a different approach .. How can I display the data into the popover div. 是否有可能返回特定div的全部数据和innerhtml,或者我必须采用不同的方法..如何将数据显示到popover div中。
The code snippet is below I am just sending a dummy value as '4' just to check, 下面的代码段是我要发送的虚拟值“ 4”来检查的,
account.php account.php
In this page I am using a popover to display content processed via ajax 在此页面中,我使用弹出窗口来显示通过ajax处理的内容
<a id="popover" href="#" data-trigger="hover" rel="popover" ><img class="img-thumbnail" src="../xxx/xxx/abc.jpg" width="50"/></a>
<div id="popajax">
</div>
jquery jQuery的
<script type="text/javascript">
$(function()
{
$("#popover").mouseover(function()
{
var textcontent = '4';
$.ajax({
type:'GET',
url: "/getuserdetails.php",
data: {myval:textcontent},
cache: true,
error: function(){
alert ("ERROR");
},
success: function(html)
{
$("#popajax").after(html);
}
});
return false;
});
});
</script>
popover script 弹出脚本
<script>
$(function () {
$("#popover").popover({ trigger: "hover",
html: true,
placement : 'top',
content: function() {
return $('#popover_content').html();
},
title: function() {
return $('#popover_title').html();
}
});
});
</script>
getuserdetails.php getuserdetails.php
<?php session_start();
include('include/functions.php'); /* This is for crud and other functions*/
if(isset($_GET['myval']))
{
$sql = sql::readOne("SELECT * FROM table_name WHERE id='$_GET[myval]'");
}
?>
<div id="popover_title" class="hide" >
<h4><?php echo $sql[0]->username ?></h4>
</div>
<div id="popover_content" class="hide" >
<div> <p> This is Atul Joshi</p></div>
</div>
*Something Like this *像这样的东西
If you would like put your result inside <div id="popajax"> </div>
如果您想将结果放入<div id="popajax"> </div>
You can use html()
function to insert the element. 您可以使用html()
函数插入元素。
success: function(data){
$("#popajax").html(data);
}
You can get the html of particular element by using this function. 您可以使用此函数获取特定元素的html。 like 喜欢
$(element).html()
Or If you want to get inner text of particular element then you can use. 或者,如果您想获取特定元素的内部文本,则可以使用。
$(element).text()
To receive html code and display as html text. 接收html代码并显示为html文本。 You should use .html()
您应该使用.html()
$('SELECTOR').html('<STRONG>html data</STRONG>');
To display it as text, simple .text()
is enough 要将其显示为文本,简单的.text()
就足够了
$('*SELECTOR*').text('your text goes here');
Those were for setting values for a selector. 这些用于设置选择器的值。
To get html or text from a selector in jquery 从jQuery中的选择器获取html或文本
Simple $('SELECTOR').html(); $('SELECTOR').text();
简单的$('SELECTOR').html(); $('SELECTOR').text();
$('SELECTOR').html(); $('SELECTOR').text();
does the work. 做工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.