[英]Load a data from a page to another page using jquery ajax
我有兩個頁面, index.php和block1.php我想將block1.php中的數據加載到index.php中的div #details
這是我的代碼
的index.php
<div id="pop_box">
<div class="close"><span id="close">×</span></div>
<div id="block"></div>
<div id="details"></div>
</div>
block1.php
<script>
$(document).ready(function() {
var lnk;
$('[href]').click(function() {
lnk = '';
lnk = $(this).attr('href');
if (lnk.charAt(1) == "b") {
var lot = lnk;
$.ajax({
url: "2dmap_func.php",
method: "POST",
dataType: "text",
data: {
lot: lot
},
success: function(data) {
//alert(data);
$('index.php #pop_box #details').load(data);
}
});
}
});
});
</script>
正如您所看到的,我想將block1.php中的數據加載到index.php的div#詳細信息,此代碼不起作用。
$('index.php #pop_box #details').load(data);
在你index.php中添加以下行:
<?php include_once 'block1.php' ?>
在你的block1.php中更改以下行:
$('index.php #pop_box #details').load(data);
至
$('#details').html(data); // if data is valid html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.