从包含的页面调用未定义的函数

时间:2013-02-13 14:14:26

标签: javascript asp.net-mvc

当我从我的链接调用搜索功能(在下面观看)并从document.ready开始工作时发生错误 我读过我可能有语法错误,但我无法找到它。 这是我的代码:     

varchevron = true;

function details(value) {
    $("#windows").load('/Banc/Details/' + value);
}

function edit(value) {
    $("#windows").load('/Banc/Edit/' + value);
}

function create() {
    $("#windows").load('/Banc/Create');
}

function del(value) {
    $("#windows").load('/Banc/Delete/' + value);
}

function search(page, triCol) {

    var ajaxRequest;

    try {
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e) {
        // Internet Explorer
        try {
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                // Erreur
                alert("Erreur du navigateur");
                return false;
            }
        }
    }
    // Reception des donnees
    ajaxRequest.onreadystatechange = function () {
        if (ajaxRequest.readyState == 4) {
            //alert(ajaxRequest.responseText);
            document.getElementById('tab_result').innerHTML = ajaxRequest.responseText;               
        }
    }

    var type = $("#typeSearch").val();
    var contain = $("#containSearch").val();
    var txt = $("#txtSearch").val();
    var pageSize = 50;
    if (txt == "") {
        type = "default";
    }       
    var queryString = "/" + page + "/" + pageSize + "/" + triCol + "/" + type + "/" + contain + "/" + txt;
    //alert(queryString);
    ajaxRequest.open("GET", "/Banc/Table" + queryString, true);
    ajaxRequest.send(null); 
}

function chevron() {       
    if (varchevron) {
        $("#i-chevron").removeClass("icon-chevron-down");
        $("#i-chevron").addClass("icon-chevron-up");
        varchevron = false;
    }
    else {
        $("#i-chevron").removeClass("icon-chevron-up");
        $("#i-chevron").addClass("icon-chevron-down");
        varchevron = true;
    }
}

$(document).ready(function () {
    $("#btnBanc").addClass("active");
    search(0, 0);
});
</script>

我的电话名为Table:

<div class="pagination" style="text-align:center">
<ul>        
    @if (Model.HasPreviousPage)
    {
        <li id="prvpage"><a onclick="search(@(Model.PageIndex - 1), @Model.Tricol)"><img src='~/Images/Arrow_Previous.jpg' alt=""/></a></li>
        if (Model.PageIndex == 1)
        {
            <li><a href="#" onclick="search(@(Model.PageIndex - 1), @Model.Tricol)">@(Model.PageIndex)</a></li>
        }
        else
        {
            <li><a href="#" onclick="search(@(Model.PageIndex - 2), @Model.Tricol)">@(Model.PageIndex - 1)</a></li>
            <li><a href="#" onclick="search(@(Model.PageIndex - 1), @Model.Tricol)">@(Model.PageIndex)</a></li>
        }
    }
    <li class="disabled"><a>@(Model.PageIndex + 1)</a></li>
    @if (Model.HasNextPage)
    {   
        <li><a href="#" onclick="search(@(Model.PageIndex + 1), @Model.Tricol)">@(Model.PageIndex + 2)</a></li>
        if (Model.Has2NextPage)
        {
            <li><a href="#" onclick="search(@(Model.PageIndex + 2), @Model.Tricol)">@(Model.PageIndex + 3)</a></li>
        }
        <li id="nxtpage"><a onclick="search(@(Model.PageIndex + 1))"><img src='~/Images/Arrow_Next.jpg' alt=""/></a></li>
    }

</ul>
</div>

这里有什么问题? 谢谢你的帮助。

编辑:

我重新设计了我的搜索功能:

function search(page, triCol) {

    var type = $("#typeSearch").val();
    var contain = $("#containSearch").val();
    var txt = $("#txtSearch").val();
    var pageSize = 50;
    if (txt == "") {
        type = "default";
    }
    var queryString = "/" + page + "/" + pageSize + "/" + triCol + "/" + type + "/" + contain + "/" + txt;

    $.ajax({
        type: "GET",
        url: "/Banc/Table" + queryString,
        success: function (html) {
            document.getElementById('tab_result').innerHTML = html;
        },
        error: function(XMLHttpRequest, textStatus, errorThrows){

        }
    });
}

然而,错误:“调用未定义的函数”在执行时仍保留:

<li id="nxtpage"><a onclick="search(@(Model.PageIndex + 1))"><img src='~/Images/Arrow_Next.jpg' alt=""/></a></li>

从以下工作:

$(document).ready(function () {
    $("#btnBanc").addClass("active");
    search(0, 0);
});

0 个答案:

没有答案