weixin_33716154 2015-11-22 13:25 采纳率: 0%
浏览 34

Ajax呼叫刷新页面

I have a list of elements in a gridview and I need to delete them with web-method, update gridview and don't reload the whole page. But after every call the page reloads.

My button:

<asp:Button ID="btnDelete" runat="server"  CssClass="btn btn-default" Text="Delete a row" OnClientClick="DeleteRecord() return false;" />

JS-script for it:

function DeleteRecord() {
    var inputData = jsTextBox();
    if (confirm('Are you certain you want to delete this record?')) {
        $.ajax({
            type: "POST",
            url: "SubjectTable.aspx/DeleteRecord",
            data: inputData,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {
                $('#<%=gdViewSubj.ClientID%>').empty();
                if (data.d.length > 0) {
                    fillGrid(data);
                }
            },
            failure: function (data) {
                alert(data.d);
            }
        });
    }
    return false;
}
function fillGrid(data) {
    $('#<%=gdViewSubj.ClientID%>').append("<tr><th>SUBJ_ID</th><th>SUBJ_NAME</th><th>HOUR</th><th>SEMESTER</th></tr>");
    for (var i = 0; i < data.d.length; i++) {
        $('#<%=gdViewSubj.ClientID%>').append("<tr><td>" +
                    data.d[i].SUBJ_ID + "</td> <td>" +
                    data.d[i].SUBJ_NAME + "</td> <td>" +
                    data.d[i].HOUR + "</td> <td>" +
                    data.d[i].SEMESTER + "</td></tr>");
    }
}

So when I check the script step by step, I see that everything's fine, gridview is cleared and then filled without deleted row. But after end of the script page reloads and I see the old row. If I close page and open it again, then I get an updated table.

What is the root of this issue and how to fix it?

  • 写回答

2条回答 默认 最新

  • weixin_33730836 2015-11-22 13:34
    关注

    Your onclick function:

    DeleteRecord() return false;
    

    will throw an error:

    Unexpected token return

    You need to end your first statement with a semi-colon.

    DeleteRecord(); return false;
    
    评论

报告相同问题?