dongzhisang5342 2011-06-15 11:27
浏览 25
已采纳

动态地将新记录添加到MySQl - 淡出旧显示,但更新的数据不会淡入

I will try and explain my problem as accurately as possible, I don't think a JSFiddle will help in this case.

What I have is a page where all records of a database table are shown and a form to add a new record.

Once the form is filled in and submitted, the new record is added to the database correctly and the old html table is faded out to allow for the new table to be faded in but this is where it breaks and I am left with a blank section where the table should be.

Appropriate code below:

gigs.php:

$(".comment_button").click(function() {

$('#gigs').fadeOut(1000).empty();

var dateval = $("#date").val();
var venueval = $("#venue").val();
var timeval = $("#time").val();
var untilval = $("#until").val();
var mapval = $("#map").val();


var dataString = 'date='+ dateval + '&venue='+ venueval + '&time='+ timeval + 'until='+ untilval + 'map='+ mapval;

if(dateval=='')
{
    alert("Please select the date of the gig");
}
else if(venueval=='')
{
    alert("Please enter a venue");
}
else if(timeval=='')
{
    alert("Please select a start time");
}
else if(untilval=='')
{
    alert("Please enter a finish time");
}
else
{
    $("#flash").show();
    $("#flash").fadeIn(400).html('<img src="images/loading.gif" align="absmiddle">&nbsp;<span class="loading">Updating Gigs...</span>');

    $.ajax({
        type: "POST",
        url: "add-gigs.php",
        data: dataString,
        cache: false,
        success: function(html){
            $("gigs").prepend(html).fadeIn(1000);
            $("#flash").fadeOut(1000);  
        }
    });
}
return false;
});
});

The form to add the new record:

<form  method="post" name="form" action="">
                <fieldset>
                <legend>Add Gig</legend>
                <span class="add-gig-label-venue">Venue:</span>  <input type="text" name="venue" id="venue" maxlength="100" /><br />
                <span class="add-gig-label-date">Date:</span>  <input type="text" name="date" id="date" maxlength="10" />
                <span class="add-gig-label-start">Start Time:</span>  <input type="text" name="time" id="time" maxlength="5" />
                <span class="add-gig-label-end">End Time:</span>  <input type="text" name="until" id="until" maxlength="5"/> <br />
                <span class="add-gig-label-map">Google Maps URL:</span>  <input type="text" name="map" id="map" />
                <input type="submit"  value="Add Gig"  id="v" name="submit" class="comment_button"/>
                </fieldset>
            </form>

and below this is the div to show an ajax loading gif called flash and the table where the current records are shown:

<div id="flash" align="left" ></div>
<div id="gigs"> <!-- div that is emptied -->
<!-- Start the table -->
<table class="gig-table" cellspacing="0" cellpadding="0">
<!-- table data -->
</table>
</div> <!-- end 'gigs' div -->

The other file, add-gigs.php simply takes the POST variables and created a MySQL query to insert the new record and then has the same php code for the table as it is in the other file but obviously this one will now include the newly added row.

It is this table that I cannot get to fade in.

I hope that makes sense, otherwise I will try and elaborate further.

  • 写回答

1条回答 默认 最新

  • dsxi70423 2011-06-15 11:32
    关注

    You forgot the "#" in $("gigs")

        success: function(html){
            $("#gigs").prepend(html).fadeIn(1000);
            $("#flash").fadeOut(1000);  
        }
    

    As just $("gigs"), it means to look for a <gigs> element on the page. The "#" prefix means to look for an element by "id" value.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题