簡體   English   中英

從下拉列表中選擇Ajax調用

[英]Ajax call from dropdown select

我正在嘗試向下拉菜單中指定的頁面發出Ajax請求。 我已經成功地將我的大部分腳本代碼用於將鼠標單擊綁定到表行,但是在這種情況下,當我在此處嘗試操作時,它將無法正常工作。 我收到ReferenceError:未定義fnsuccess。 當我使用此腳本的大部分來綁定鼠標單擊時,沒有得到此ReferenceError。

    <script type="text/javascript">
            function isValid(frm){
                $("#courseinfo").hide();
                $("#frm").validate();

                var four04 = $("#frm :selected").val();
                console.log('Testing console');

                if (four04 == "404")
                {
                    console.log("404");
                    var txt = ($(this).text());

                    $.ajax({url:"404.json", data:{coursename:txt}, type:"GET", dataType:"json",
                    success:fnsuccess, error:fnerror});

                    function fnsuccess(serverReply) {
                        if (serverReply && serverReply.info) {
                            $("#infohere").text(serverReply.info);
                            $("#courseinfo").show();
                        } else
                        fnerror();
                    }
                    function fnerror() {
                        alert("Error occurred");
                        $("#courseinfo").hide();
                    }                   
                }
                else
                {
                    console.log("else 404");
                }
        }
    </script>
課程->評分404錯誤403錯誤

固定:

  <script> function isValid(frm){ $("#otherPageContent").hide(); $("#frm").validate(); var dropDownSelected = $("#frm :selected").val(); if (dropDownSelected == "404") { var txt = ($(this).text()); $.ajax({url:"404_error.json", data:{coursename:txt}, type:"GET", dataType:"json", success:fnsuccess, error: function(xhr, status, error){ $("#infohere").text( "The requested page was: 404_error.json" + ". The error number returned was: " + xhr.status + ". The error message was: " + error); $("#otherPageContent").show(); } }); // end of ajax } // end of if 404 function fnsuccess(serverReply) { if (serverReply && serverReply.info) { $("#infohere").text(serverReply.info); $("#otherPageContent").show(); } } return false; // pause message on screen } </script> 

isValid function外部定義function fnsuccess(serverReply)fnerror

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM