简体   繁体   English

$未在我的JavaScript上定义为具有多个函数,并且每个函数中都包含ajax

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

Im am using Microsoft Edge in the scenario. 我在方案中使用Microsoft Edge。

I as able to successfully do a single function with a ajax syntax with this code: 我能够使用此代码成功使用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>

However when I insert addition functions with their on ajax inside the function I am receiving $ is not defined error function monitorOccupy() as shown below: 但是,当我在接收到$的函数中的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>

I have no idea my is this error is showing up on my console. 我不知道我的控制台上显示此错误。

Call these functions as below 如下调用这些函数

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

Before posting this question the only jQuery file in my html file was jquery.min.js 在发布此问题之前,我的html文件中唯一的jQuery文件是jquery.min.js

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

After inserting another jquery.min.js file my problem is solved. 插入另一个jquery.min.js文件后,我的问题解决了。 This is what it looks now: 现在看起来是这样:

<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