[英]jQuery pop up showing old content not the new content
I have a problem with jQuery pop up. jQuery弹出窗口出现问题。 I have some content load by ajax. 我有一些由ajax加载的内容。 And I want that content to be a pop up message (onclick event). 我希望该内容成为弹出消息(onclick事件)。 On the first time whenever I click the popup link it shows correct content. 每当我单击弹出链接时,它都会显示正确的内容。 And after loading content(in Ajax) first time it shows correct content, But next time whenever I click the popup link it shows old content that loaded at first time. 并且在第一次加载内容之后(在Ajax中)它显示正确的内容,但是下次每次我单击弹出链接时,它都显示第一次加载的旧内容。 Here is code.. 这是代码。
<div id="company">
<div class="video-text">
<script>
function popup () {
$( "#dialog" ).dialog({
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
};
</script>
<?php if (!empty($video_details)) {?>
<p><?php echo $video_details['companyName'];?></p>
<span class="txt-small"><?php
$company_desc = $video_details['companyDesc'];
echo substr("$company_desc", 0, 60);
//echo $company_desc;
?>
</span>
<input type="submit" onclick="popup()" value="Read more..">
<div id="dialog" title="Read more..">
<p><?php echo $company_desc;?></p>
</div>
<?php }?>
</div>
Ajax : 阿贾克斯:
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("company").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","http://172.16.1.181:85/mydomain/home/load_company/",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
var data = 'id='+current.id;
xmlhttp.send(data);
//alert(current.id);
}
Here I post my id to the load_company
controller, it render the content and load in company
div .. The load the all content in company div 在这里,我将我的ID发布到load_company
控制器,它将呈现内容并将其加载到company
div中。将所有内容加载到company div中
The <p><?php echo $company_desc;?></p>
contain popup content .. Here is my firebug post <p><?php echo $company_desc;?></p>
包含弹出内容..这是我的萤火虫帖子
id 213
Response 响应
<div id="company">
<div class="video-text">
<script>
function popup () {
$( "#dialog" ).dialog({
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
};
</script>
<span class="txt-small">Lorem Ipsum is simply dummy text of the printing and typeset
</span>
<input type="submit" onclick="popup()" value="Read more..">
<div id="dialog" title="Read more..">
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
</div>
</div>
Thanks in advance..!! 提前致谢..!!
Your popup();
您的popup();
function only shows the dialog box, you need to make this function do the ajax request as well, before showing the dialog. 函数仅显示对话框,在显示对话框之前,您还需要使此函数执行ajax请求。
Also, can I ask why you are not using jQuery for AJAX , seeing as you already seem to be using the library? 另外,请问您为什么不使用jQuery for AJAX ,因为您似乎已经在使用该库了?
Something like: 就像是:
function popup () {
$.post( "test.php", { id: current.id }, function( data ) {
$("#company").innerHTML=data;
$( "#dialog" ).dialog({
modal: true,
buttons: {
Ok: function() {
$( this ).dialog( "close" );
}
}
});
});
}
Also you will need to set an ID on the content element: <p id="content"><?php echo $company_desc;?></p>
另外,您将需要在content元素上设置一个ID: <p id="content"><?php echo $company_desc;?></p>
Submit button is just popping up the div named "dialog". 提交按钮只是弹出名为“对话框”的div。 have a look at your function which is responsible for updating the variable $company_desc. 看一下您的函数,该函数负责更新变量$ company_desc。
What I guess is that your if (!empty($video_details)) statement is not letting you update company_desc variable. 我猜是您的if(!empty($ video_details))语句不允许您更新company_desc变量。 Change your logic. 改变你的逻辑。
在Ater Ajax中,您必须更新对话框div,但是在代码中,您必须更新公司div,并显示对话框div。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.