Home > OS >  Uncaught ReferenceError: 'xxxxxx' is not defined
Uncaught ReferenceError: 'xxxxxx' is not defined

Time:06-06

Trying to pass a data via onclick event and keeps saying "Uncaught ReferenceError: 'xxxxxx' is not defined"

   var ViewDetails = function (insuredID) {
        $.ajax({
            type: "GET",
            url: "/Exposure/ViewDetails",
            data: {'InsuredID': insuredID},
            success: function (response) {
              
            }
        })
    }
<button type="submit"  onclick="ViewDetails(@item.Identifier)">

CodePudding user response:

Do like this:

<button type="submit"  data="@item.Identifier">

$('.button_class').click(function() {
  const data = $(this).attr('data');
  $.ajax({
    type: "GET",
    url: "/Exposure/ViewDetails",
    data: {'InsuredID': data},
    success: function (response) {
              
    }
  })
});
  • Related