簡體   English   中英

$未在我的JavaScript上定義為具有多個函數,並且每個函數中都包含ajax

[英]$ is not defined on my javascript with multiple function and ajax inside each function

我在方案中使用Microsoft Edge。

我能夠使用此代碼成功使用ajax語法完成單個功能:

<script>
    document.getElementById("inputEventID").onchange = function () { myFunction() };

    function myFunction() {
        $.ajax({
        type: 'post',
        url: 'webFetchMax.php',
        data: {
            eventID: form.eventID.value
        },
        success: function (response) {
            $('#divSlots').html(response);
        }
    });
    }
</script>

但是,當我在接收到$的函數中的ajax上插入附加函數時, 未定義錯誤函數monitorOccupy() ,如下所示:

<script>
    document.getElementById("inputEventID").onchange = function () { myFunction() };

    monitorOccupy();
    monitorAvail();
    function monitorOccupy() {
        $.ajax({
        type: 'post',
        url: 'webFetchMax.php',
        data: {
            eventID: form.eventID.value
        },
        success: function (response) { 
            $('#oSlots').html(response);
        },
        complete: function() {
            setTimeout(monitorOccupy,1000);
        }
    });
    }
    function monitorAvail() {
    }

    function myFunction() {
        $.ajax({
        type: 'post',
        url: 'webFetchMax.php',
        data: {
            eventID: form.eventID.value
        },
        success: function (response) {
            $('#divSlots').html(response);
        }
    });
    }
</script>

我不知道我的控制台上顯示此錯誤。

如下調用這些函數

$(document).ready(function(){monitorOccupy(); MonitorAvail();});

在發布此問題之前,我的html文件中唯一的jQuery文件是jquery.min.js

<script scr="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>

插入另一個jquery.min.js文件后,我的問題解決了。 現在看起來是這樣:

<script scr="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>

暫無
暫無

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

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