我有三个div,如何只在一个特定的div加载数据而不重新加载php-codeigniter中的完整页面?
我有三个div标签,点击链接我只想在第二个div中加载数据而不加载完整的页面,我想保持第一个和第三个div为静态,第二个div应该是动态的?
<a href="https://stackoverflow.com/questions/27181819/i-have-three-divs-how-to-load-data-in-only-a-particular-div-without-reloading/patientLogin/patientVisit_details/patient_visit_id;?>">hospital_name;?> //content// //content//
你可以通过ajax实现这些目标。
1) As you want to apply dynamic data loading on some click event of some anchor link then please don't apply anchor link as: "hospital_name;?>" the anchor leads you to the href value link. alternatively you can do like ();
现在你的CI案例; 在视图中:
hospital_name;?>
在Js文件中
function changeData(parentVisitId){ var urlCI = 'patientLogin/patientVisit_details/'+parentVisitId; $.ajax({ type: "GET", url: urlCI, data:{ 'parenIdIfReq':parentVisitId, }, success: function(response) { if(response!=''){ $('.second').html(response); } else{ return false; } } }); } In controller/action ie patientLogin/patientVisit_details/parentVisitedId function patientVisit_details($parentVisiteId){ echo "whatever data you want to return as response"; }
只是尝试从ajax
函数返回你需要的值。像这样的东西可能会做。你有一个insert.php
文件,你可以echo or return
需要填充到页面的function
末尾的data
$('.first a').click(function(){ $.ajax({ type: "POST", url: "insert.php", cache: false, success: function(data){ //Now you have obtained the data that was was returned from the function //if u wish to insert the value into an input field try $('.second').html(data); //now the data is populated in the input field } }); })
有关更多信息,请查看此链接