【发布时间】:2014-01-17 11:03:47
【问题描述】:
在 iframe 加载完成后,我想在 ID 为 main 的 div 中加载 pictures.php...
这是我的 index.php:
<html>
<head>
<script src='jquery.min.js' ></script>
<script src='upload.js' ></script>
</head>
<body>
<div id='main' ><?php include("pictures.php"); ?></div>
<form action='upload.php' target='tar_wp' enctype='multipart/form-data' method='POST' >
<iframe src='' name='tar_wp' width='0' height='0' onload='tar_wp()' ></iframe>
<input type='file' name='pic' id='pic' />
<button type='submit' id='submit' >submit</button>
</form>
</body>
</html>
还有我的pictures.php:
<?php
$img = mysql_query("SELECT * FROM images");
while($rows_img = mysql_fetch_assoc($img)){
$i_img = $rows_img['image_path'];
}
echo "<img src='$i_img' width='200px' height='200px' />";
?>
upload.php 完美运行,它插入了我需要的图像,只是加载不起作用....
我使用 iframe 作为目标以避免加载整个页面,而是仅加载 id 为 main...的 div...
这是我的upload.js:
$(document).ready(function(){
$("#submit").click(function{
var pic = $("#pic").val();
if(pic == ""){
$("#pic").focus();
}
else{
$.ajax({
type: 'post',
success: function () {
$("#main").load("index.php"); // load div to see changes after uploading
}
});
}
});
});
不幸的是,它不会加载 div 来查看新的上传内容。我必须刷新整个页面才能看到新的上传。我也在 iframe onload event 上尝试过这段代码:
function tar_wp(){
$("#main",window.parent.document).load("pictures.php");
}
任何想法都非常感谢,在此先感谢....
顺便说一句,我的主要目标是在 iframe 加载完成后,在 id main 的 div 中加载pictures.php...
【问题讨论】:
-
我认为 tar_wp 在您的父文档中,但在您尝试应用父 dpocuments 函数的函数中...