为什么我的网页突然刷新

时间:2017-05-02 10:57:36

标签: javascript asp.net-mvc model-view-controller kendo-ui

我正在使用Kendo GridView。调用onSearch函数后,网页会突然刷新。我该如何解决这个问题?

这是我的网格:

$("#grid").kendoGrid({
        selectable: "row",
        scrollable: false,
        autoBind: false,
        columns: [
                { title: "Status", width: '200px', template: '#if(Allowed){#Yes#}else{#No#}#' },
                { title: "Description", field: "Message" }
        ],
        dataSource: vm.entity.MyDataSource
    });

这是我的代码:

entity: {
            MyDataSource: new kendo.data.DataSource({
                transport: {
                    read: {
                        dataType: "json",
                        type: 'POST',
                        url: 'url goes here...',
                        data: {
                            code: function () { return '123' }
                        }
                    }
                },
                schema: {
                    data: "Data",
                    parse: function (data) {
                        return data;
                    }
                }
            }),

            onSearch: function () {
                vm.entity.MyDataSource.read();
            }
        }

一切正常,结果正确返回,GridView充满了数据,但1秒后网页突然刷新。

2 个答案:

答案 0 :(得分:0)

看起来当你调用onSearch()函数时,你也会导航到url。检查是否未通过以下方式调用搜索功能:

与href和onclick函数链接:

<a href="" onclick="search()" />
表单内的

按钮:

<form>
    <button onclick="search">Search</button>
</form>

答案 1 :(得分:0)

我解决了这个问题。我的按钮类型设置为&#39;提交&#39;。我把它改成了按钮&#39;现在一切都很好。