Uncaught ReferenceError: javascriptFunction is not defined at HTMLAnchorElement.onclick exception

I try to implement a simple calendar in ASP.NET MVC 4. Its aim is to view a day and schedule meetings among different units of an organization. I am getting “Uncaught ReferenceError: GetDayViewJS is not defined” exception. Backend side of the project has passed the tests. Here is the Razor view of the erroneous page:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@model ToplantiOrganizasyon.Viewler.Somut.TimeFrameView
@{
ViewBag.Title = "Meeting Organization";
}
<meta charset="utf-8">
<title>Dynamic Calendar JavaScript | CodingNepal</title>
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Google Font Link for Icons -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,[email protected],100..700,0..1,-50..200">
<script src="script.js" defer></script>
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script>
function GetDayViewJS(dayId, monthId) {
debugger;
var url ="/Home/GetDayView?dayId=" + dayId;
$("#MyModal2").modal();
$.ajax({
url:url,
type:"get",
success:function(data)
{
var obj=JSON.parse(data);
$("#id").val(obj.ID);
$("#Kategori").val(obj.Kategori);
$("#Aciklama").val(obj.Aciklama);
}
/*
complete: function(){
Hide(); // Hide loader icon
},
*/
/*
error: function (jqXHR, textStatus, errorThrown) {
alert("HTTP Status: " + jqXHR.status + "; Error Text: " + jqXHR.responseText); // Display error message
}
*/
failure: function (jqXHR, textStatus, errorThrown) {
alert("Status: " + jqXHR.status + "; Error: " + jqXHR.responseText); // Display error message
}
});
}
</script>
<div id="sample-overview">
<header>
<p class="current-date"></p>
<div class="icons">
<span id="prev" class="material-symbols-rounded">chevron_left</span>
<span id="next" class="material-symbols-rounded">chevron_right</span>
</div>
</header>
<div class="calendar">
<p class="calendar">@Model.Definition</p>
<ul class="weeks">
<li>Monday</li>
<li>Tuesday</li>
<li>Wedn.</li>
<li>Thursday</li>
<li>Friday</li>
<li>Saturday</li>
<li>Sunday</li>
</ul>
<ul class="days">
@*This is the start of the erroneous lines*@
<li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(1,7)>1</a></li>
<li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(2,7)>2</a></li>
<li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(3,7)>3</a></li>
<li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(4,7)>4</a></li>
<li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(5,7)>5</a></li>
<li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(6,7)>6</a></li>
<li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(7,7)>7</a></li>
<li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(8,7)>8</a></li>
<li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(9,7)>9</a></li>
<li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(10,7)>10</a></li>
@*This is the end of the erroneous lines*@
<li>11</li>
<li>12</li>
<li>13</li>
<li>14</li>
<li>15</li>
<li>16</li>
<li>17</li>
<li>18</li>
<li>19</li>
<li>20</li>
<li>21</li>
<li>22</li>
<li>23</li>
<li>24</li>
<li>25</li>
<li>26</li>
<li>27</li>
<li>28</li>
<li>29</li>
<li>30</li>
<li>31</li>
<li>32</li>
<li>33</li>
<li>34</li>
<li>35</li>
</ul>
</div>
</div>
</code>
<code>@model ToplantiOrganizasyon.Viewler.Somut.TimeFrameView @{ ViewBag.Title = "Meeting Organization"; } <meta charset="utf-8"> <title>Dynamic Calendar JavaScript | CodingNepal</title> <link rel="stylesheet" href="style.css"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <!-- Google Font Link for Icons --> <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,[email protected],100..700,0..1,-50..200"> <script src="script.js" defer></script> <script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script> <script> function GetDayViewJS(dayId, monthId) { debugger; var url ="/Home/GetDayView?dayId=" + dayId; $("#MyModal2").modal(); $.ajax({ url:url, type:"get", success:function(data) { var obj=JSON.parse(data); $("#id").val(obj.ID); $("#Kategori").val(obj.Kategori); $("#Aciklama").val(obj.Aciklama); } /* complete: function(){ Hide(); // Hide loader icon }, */ /* error: function (jqXHR, textStatus, errorThrown) { alert("HTTP Status: " + jqXHR.status + "; Error Text: " + jqXHR.responseText); // Display error message } */ failure: function (jqXHR, textStatus, errorThrown) { alert("Status: " + jqXHR.status + "; Error: " + jqXHR.responseText); // Display error message } }); } </script> <div id="sample-overview"> <header> <p class="current-date"></p> <div class="icons"> <span id="prev" class="material-symbols-rounded">chevron_left</span> <span id="next" class="material-symbols-rounded">chevron_right</span> </div> </header> <div class="calendar"> <p class="calendar">@Model.Definition</p> <ul class="weeks"> <li>Monday</li> <li>Tuesday</li> <li>Wedn.</li> <li>Thursday</li> <li>Friday</li> <li>Saturday</li> <li>Sunday</li> </ul> <ul class="days"> @*This is the start of the erroneous lines*@ <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(1,7)>1</a></li> <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(2,7)>2</a></li> <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(3,7)>3</a></li> <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(4,7)>4</a></li> <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(5,7)>5</a></li> <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(6,7)>6</a></li> <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(7,7)>7</a></li> <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(8,7)>8</a></li> <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(9,7)>9</a></li> <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(10,7)>10</a></li> @*This is the end of the erroneous lines*@ <li>11</li> <li>12</li> <li>13</li> <li>14</li> <li>15</li> <li>16</li> <li>17</li> <li>18</li> <li>19</li> <li>20</li> <li>21</li> <li>22</li> <li>23</li> <li>24</li> <li>25</li> <li>26</li> <li>27</li> <li>28</li> <li>29</li> <li>30</li> <li>31</li> <li>32</li> <li>33</li> <li>34</li> <li>35</li> </ul> </div> </div> </code>
@model  ToplantiOrganizasyon.Viewler.Somut.TimeFrameView

@{
    ViewBag.Title = "Meeting Organization";
}

<meta charset="utf-8">
<title>Dynamic Calendar JavaScript | CodingNepal</title>
<link rel="stylesheet" href="style.css">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Google Font Link for Icons -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Rounded:opsz,wght,FILL,[email protected],100..700,0..1,-50..200">
<script src="script.js" defer></script>
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>

<script>

    function GetDayViewJS(dayId, monthId) {

        debugger;

        var url ="/Home/GetDayView?dayId=" + dayId;

        $("#MyModal2").modal();

        $.ajax({

            url:url,
            type:"get",
            success:function(data)
            {
                var obj=JSON.parse(data);
                $("#id").val(obj.ID);
                $("#Kategori").val(obj.Kategori);
                $("#Aciklama").val(obj.Aciklama);

            }

    /*
            complete: function(){
                Hide(); // Hide loader icon
            },
    */

    /*
            error: function (jqXHR, textStatus, errorThrown) {
                alert("HTTP Status: " + jqXHR.status + "; Error Text: " + jqXHR.responseText); // Display error message
            }
    */

            failure: function (jqXHR, textStatus, errorThrown) {
                alert("Status: " + jqXHR.status + "; Error: " + jqXHR.responseText); // Display error message
            }


        });

    } 

</script>

<div id="sample-overview">
    <header>
        <p class="current-date"></p>
        <div class="icons">
            <span id="prev" class="material-symbols-rounded">chevron_left</span>
            <span id="next" class="material-symbols-rounded">chevron_right</span>
        </div>
    </header>
    <div class="calendar">
        <p class="calendar">@Model.Definition</p>
        
        <ul class="weeks">
            <li>Monday</li>
            <li>Tuesday</li>
            <li>Wedn.</li>
            <li>Thursday</li>
            <li>Friday</li>
            <li>Saturday</li>
            <li>Sunday</li>
        </ul>
        <ul class="days">

            @*This is the start of the erroneous lines*@
            <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(1,7)>1</a></li>
            <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(2,7)>2</a></li>
            <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(3,7)>3</a></li>
            <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(4,7)>4</a></li>
            <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(5,7)>5</a></li>
            <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(6,7)>6</a></li>
            <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(7,7)>7</a></li>
            <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(8,7)>8</a></li>
            <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(9,7)>9</a></li>
            <li><a href='#' @*class='btn btn-success'*@ onclick=GetDayViewJS(10,7)>10</a></li>
            @*This is the end of the erroneous lines*@
            <li>11</li>
            <li>12</li>
            <li>13</li>
            <li>14</li>
            <li>15</li>
            <li>16</li>
            <li>17</li>
            <li>18</li>
            <li>19</li>
            <li>20</li>
            <li>21</li>
            <li>22</li>
            <li>23</li>
            <li>24</li>
            <li>25</li>
            <li>26</li>
            <li>27</li>
            <li>28</li>
            <li>29</li>
            <li>30</li>
            <li>31</li>
            <li>32</li>
            <li>33</li>
            <li>34</li>
            <li>35</li>
        </ul>
    </div>

</div> 

The main aim of the GetDayViewJS is to get the time frame of the selected day and month through an Ajax call. The time frame of the day consists of the meetings and other events that take place on a specific day. After an Ajax call, it is supposed to reflect the data into divDayPresence div, however, it is not the present concern. GetDayViewJS is supposed to hit the function GetDayView function defined at the HomeController. Here is the definition of the GetDayView function of the HomeController:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public JsonResult GetDayView(int dayId)
{
try
{
int monthId = 7;
if (dayId < 0 || monthId < 0)
throw new ArgumentException(String.Format("dayId:{0} monthId:{1}", dayId, monthId));
DateTime day = this._dateTimeAffairs.CreateDateTime(dayId, monthId, DateTime.Now.Year);
if (day == DateTime.MinValue)
throw new InvalidOperationException(String.Format("day == DateTime.MinValue. day:{0}", day.ToString()));
DayView dayView = this._dateTimeAffairs.CreateDayView(day);
if (dayView == null)
throw new InvalidOperationException("dayView == null");
string resultValue = JsonConvert.SerializeObject(dayView, Formatting.Indented, new JsonSerializerSettings
{
//COMMENT what is this?
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
return Json(new { Status = "200", value = resultValue }, JsonRequestBehavior.AllowGet);
}
catch (ArgumentException exception)
{
//exception handling
}
catch (InvalidOperationException exception)
{
//exception handling
}
catch (NullReferenceException exception)
{
//exception handling
}
catch (Exception exception)
{
//exception handling
}
}
</code>
<code>public JsonResult GetDayView(int dayId) { try { int monthId = 7; if (dayId < 0 || monthId < 0) throw new ArgumentException(String.Format("dayId:{0} monthId:{1}", dayId, monthId)); DateTime day = this._dateTimeAffairs.CreateDateTime(dayId, monthId, DateTime.Now.Year); if (day == DateTime.MinValue) throw new InvalidOperationException(String.Format("day == DateTime.MinValue. day:{0}", day.ToString())); DayView dayView = this._dateTimeAffairs.CreateDayView(day); if (dayView == null) throw new InvalidOperationException("dayView == null"); string resultValue = JsonConvert.SerializeObject(dayView, Formatting.Indented, new JsonSerializerSettings { //COMMENT what is this? ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); return Json(new { Status = "200", value = resultValue }, JsonRequestBehavior.AllowGet); } catch (ArgumentException exception) { //exception handling } catch (InvalidOperationException exception) { //exception handling } catch (NullReferenceException exception) { //exception handling } catch (Exception exception) { //exception handling } } </code>
public JsonResult GetDayView(int dayId)
{
    try
    {

        int monthId = 7;

        if (dayId < 0 || monthId < 0)
            throw new ArgumentException(String.Format("dayId:{0} monthId:{1}", dayId, monthId));

        DateTime day = this._dateTimeAffairs.CreateDateTime(dayId, monthId, DateTime.Now.Year);

        if (day == DateTime.MinValue)
            throw new InvalidOperationException(String.Format("day == DateTime.MinValue. day:{0}", day.ToString()));

        DayView dayView = this._dateTimeAffairs.CreateDayView(day);

        if (dayView == null)
            throw new InvalidOperationException("dayView == null");

        string resultValue = JsonConvert.SerializeObject(dayView, Formatting.Indented, new JsonSerializerSettings
        {
            //COMMENT what is this? 
            ReferenceLoopHandling = ReferenceLoopHandling.Ignore
        });

        return Json(new { Status = "200", value = resultValue }, JsonRequestBehavior.AllowGet);

    }
    catch (ArgumentException exception)
    {
        //exception handling
    }
    catch (InvalidOperationException exception)
    {
        //exception handling
    }
    catch (NullReferenceException exception)
    {
        //exception handling
    }
    catch (Exception exception)
    { 
        //exception handling
    }

}

I know that GetDayView runs smoothly. The problem here is that flow never reaches the GetDayView function, in the browser’s console, I am observing the exception:

(index):127 Uncaught ReferenceError: GetDayViewJS is not defined at
HTMLAnchorElement.onclick ((index):127:56)

I wrote the script section of the razor page at the end of the razor page but no avail. Where am I wrong? Thanks in advance.

2

As CBroe points out that, when I put comma after success:function(data) {...}, it works.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật