0
@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

<script type="text/javascript">      
       
    
    function notyfy() {
        $.notify({
            message: "Hello"
        }, {
            type: 'danger'
        });
    }

    notyfy();//THis works

    
    $("#btnSave").click(function (e) {       
        savedata();
    });

    function savedata() {
        var items = new Array();
        $("#tblGRN TBODY TR").each(function () {
            var row = $(this);
            var item = {
                'PoNo': $("#PoNo").val(),
                'FundSource': $("#FundSource").val(),
                'Vote': $("#Vote").val(), 
                'Total': row.find("TD").eq(5).html(),
                'InvoiceNo': $("#InvoiceNo").val(),
                'ReceivedDate': $("#ReceivedDate").val(),
                'Note': $("#Note").val()
            }    
            items.push(item);
        });
       
        $.ajax({
            type: "POST",
            url: "/GRN/Create",
            data: JSON.stringify(items),
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (r) {
                notyfy(); //This do not work
                alert(r.responseText);
                console.log(r);
                $("#tbody").empty();
                window.location = "/GRN/Create";
            }
        });
    }
</script>

$.notify is not a function

$.notify works outside without any issue. anything I put inside the success function giving me not a function. all libraries are working fine outside the ajax. The whole script part is above. please help me to solve the issue in this.

  • You appear to be posting to a Razor page without including the Request Verification token. That will result in a 400 Bad Request. You should include the token in the AJAX request headers: https://www.learnrazorpages.com/security/request-verification#ajax-post-requests-and-json – Mike Brind Jul 27 '21 at 08:38
  • Hi @kishan thantirwatta, are you sure notify function could works well outside ajax? If it works outside, it also could work well in ajax success function. Maybe you need share how do you define the js reference? If you add reference in razor pages, did you add `@section Scripts`? More code will be helpful. – Rena Jul 29 '21 at 06:55
  • @Rena yes it works out side. – kishan thantiriwatta Aug 11 '21 at 07:47
  • @Rena I added the whole code – kishan thantiriwatta Aug 11 '21 at 14:19

0 Answers0