嘿伙计们,我正在研究“状态” - 更新程序。它有效,只有一个问题,发送状态后我必须手动重新加载页面让脚本再次运行。你可以帮我吗?这是代码:
<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:
<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>
答案 0 :(得分:0)
看起来在您第一次调用此代码后,您正在销毁#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之后创建了一个文档“ready”事件?
我想弄清楚你想要的效果。看起来你想在上传结束后(在#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);
});
});
},