gpt4 book ai didi

php - FancyBox 并在 fancybox 退出时自动加载文件

转载 作者:行者123 更新时间:2023-11-29 06:55:07 27 4
gpt4 key购买 nike

我正在尝试编写一段代码,在用户单击 fancybox 中的其中一个选项后(选择一个选项后 fancybox 将关闭)

这是我的代码

索引.php

<?php
session_start();
include('connect.php');
include('header.php');
?>

<body>
<a href="selectfield.php" id="selectfield" class="fancybox.iframe" rel="group">Field</a>:
<span id="selectedfield_label"></span>
</body>
</html>

选择字段.php

<?php
include('connect.php');
include('header.php');
?>

</head>
<body>
<div class="row">
<div class="span12">
<?php
$searchcol = mysql_query("SELECT * from searchcolumn");
while($search = mysql_fetch_array($searchcol)){ ?>
<div class="span2" style="font-size:10px">
<a href="#" id="<?php echo $search['scol_id']; ?>" class="field" name="<?php echo $search['scol_id']; ?>"><?php echo $search['advsearch_name']; ?></a>
</div>
<?php
}
?>
</div>

</body>
</html>

脚本.js

$(document).ready(function(){

$("#selectfield").fancybox();
$("#selectcondition").fancybox();

$(".field").click(function(e) {
var id = this.id;
var name = $("#" + id).attr("name");
var datastr='field='+name;
$.ajax({
url:'storefield.php',
type:"POST",
data:datastr,
dataType:"json",
success:function(result){
$("#selectedfield_label").html(result['field']['fieldname']);
parent.$.fancybox.close(true);
}//success
});//ajax
});
});

storefield.php

<?php
session_start();
include('connect.php');
$scol_id=$_POST['field'];

$query = mysql_query("SELECT * from searchcolumn where scol_id = $scol_id");
$a = mysql_fetch_array($query);

$_SESSION['fieldname'] = $a['advsearch_name'];
$_SESSION['col'] = $a['advsearch_col'];
$_SESSION['type'] = $a['advsearch_type'];

$result['field']['fieldname'] = $_SESSION['fieldname'];
$result['field']['col'] = $_SESSION['col'];
$result['field']['type'] = $_SESSION['type'];

echo json_encode($result);
?>

我能够在选择一个选项后让 fancybox 关闭,但我无法让它的名称($result['field']['fieldname'])出现在我的 fancybox 外的 div 中

我已经尝试过不同的组合,但我无法让它工作

提前致谢

这是一个示例 sql 数据

INSERT INTO searchcolumn (advsearch_name,advsearch_col,advsearch_type) VALUES ('Title','title','varchar');
INSERT INTO searchcolumn (advsearch_name,advsearch_col,advsearch_type) VALUES ('Last Name','ln','varchar');
INSERT INTO searchcolumn (advsearch_name,advsearch_col,advsearch_type) VALUES ('First Name','fn','varchar');
INSERT INTO searchcolumn (advsearch_name,advsearch_col,advsearch_type) VALUES ('Middle Name','mn','varchar');
INSERT INTO searchcolumn (advsearch_name,advsearch_col,advsearch_type) VALUES ('Gender','gender','varchar');
INSERT INTO searchcolumn (advsearch_name,advsearch_col,advsearch_type) VALUES ('Age','age','varchar');
INSERT INTO searchcolumn (advsearch_name,advsearch_col,advsearch_type) VALUES ('Birthdate','bday','date');

最佳答案

您的 fancybox 可能在 iframe 中,因此您必须使用父页面找到要写入结果的 div

parent.$("#selectedfield_label").html(result['field']['fieldname']);

关于php - FancyBox 并在 fancybox 退出时自动加载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13215203/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com