2017-06-02 44 views
-2

我有两个页面gallery.php和post-result.php ..我得到我的ajax响应在div(模态内容)这是在gallery.php在同一页我想将div值存储在一个php变量中。在同一页上调用ajax响应

<div class="modal-content"> </div> 

我的Ajax代码是:

jQuery(document).ready(function(){ 
jQuery(".varr").click(function(){ 
var dataId = jQuery(this).attr('data-id'); 
jQuery.ajax({url:"post-result.php?dataId="+dataId,cache:false, 
success:function(result){ 
jQuery(".modal-content").html(result);} 

}); 


}); }); 
+0

为什么你在回答后改变问题?你的问题的解决方案是你只需要将'jQuery(“.modal-content”).html(result);'改为'jQuery(“#modal-content”).html(result);' – Bhavin

+0

对不起.....这只是我的打字错误.....我写了ID而不是类 – varsha

+0

和我的问题是,如何通过使用ID而不是类的PHP变量 – varsha

回答

0

你不能从Ajax调用设置PHP变量数据

+0

有没有其他方式..? – varsha

+0

我可以用jQuery来做到这一点吗? – varsha

+0

基本上你不能使用JavaScript或jQuery来做它。你可以使用jQuery(“#modal-content”)。html();你可以使用jquery来设置你的“模型内容” 中的数据,因此使用相同的 。 – ImranGalib

1

变化

jQuery(".modal-content").html(result); 

jQuery("#modal-content").html(result); 
+0

div值...可以我存储在PHP变量的div值? – varsha

+0

你可以使用id或class,但是你在div中使用了id并试图使用class来设置内容。 @varsha – JYoThI

+0

哦,是的......它只是输入错误....我得到我的阿贾克斯响应模态内容的div .... – varsha