题
嗨,我工作的一个“状态” -Updater。它的工作原理,只有一个问题,发送状态我必须手动刷新页面来再次让脚本后做事。你能帮助我吗?下面的代码:
<script language="javascript">
$(document).ready(function(){
$("form#status_form").submit(function(){
var s_autor = $('#s_autor').attr('value');
var s_status = $('#s_status').attr('value');
$.ajax({
type: "POST",
url: "/admin/request.php",
data: "s_autor="+ s_autor +"& s_status="+ s_status,
success: function(){
$('#show').load("/admin/request.php").fadeIn("slow", function(){
setTimeout(function(){
$(function() {
$("#show").fadeTo("slow", 0.01, function(){
$(this).slideUp("slow", function() {
$(this).remove();
});
});
});
}, 2000);
});
},
});
return false;
});
});
</script>
所以,你知道如何编写代码的时候有可能要重复我多久点击提交按钮?脚本
顺便说一句,这里的HTML表格:
<form id="status_form" method="post" action="request.php" onsubmit="return false;">
<input type="text" id="s_autor" name="s_autor" value="<?= $user_id; ?>" style="display: none;" /><input type="text" id="s_status" name="s_status" value="Statusnachricht" /><input type="submit" value="" class="submit" id="status_submit" />
</form>
解决方案
它看起来像你第一次调用此代码后,你摧毁#show,因此,接下来的时间,没有更多的#show?我要一些评论添加到您的代码,看看我是这个正确理解:
success: function() {
// File has been successfully posted to request.php
// We are now going to GET the contents of request.php (ignoring any response from the previous POST)
// Also note, should probably put remainder of code in a callback to "load", so we can be sure it has had a chance to load!...
$('#show').load("/admin/request.php").fadeIn("slow", function(){
setTimeout(function(){
$(function() {
$("#show").fadeTo("slow", 0.01, function(){
$(this).slideUp("slow", function() {
// Note! #show is being removed from the document here. It won't be available for future events.
$(this).remove();
});
});
});
}, 2000);
});
},
祝你好运!
修改在此寻找更多一些,我注意到您在您的setTimeout后创建文档“准备就绪”事件?
我试图找出你想要的效果。它看起来像你想拥有的东西淡入上传完成(在#show
DIV)后,等待几秒钟,然后再次淡出出来? (你slideUp
充当一个淡出的元件上,所以效果将不可见。)
怎么样这样呢?
success: function() {
// File has been successfully posted to request.php
// We are now going to GET the contents of request.php (ignoring any response from the previous POST)
$('#show').load("/admin/request.php", function() {
$(this).fadeIn("slow", function() {
setTimeout(function() {
$("#show").fadeOut("slow", function() {
// don't remove #show. Just empty it for using again next time.
$(this).empty()
});
}, 2000);
});
});
},
不隶属于 StackOverflow