2017-06-02 46 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