javascript - ASP.NET MVC does not fire jQuery Ajax POST -


i made similar solutions many times, that's why i'm surprised why 1 not working. when click on link, should submit data via jquery ajax controller. instead browser open link.

here controller:

[httppost] public async task<jsonresult> hide(int id) {     mailrepository mailrep = new mailrepository();     var result = await mailrep.hidemail(id);     if (result.result == enums.issuccess.succes)     {         return json(new { issuccess = true }, jsonrequestbehavior.allowget);     }     else         return json(new { issuccess = false, dataerror = result.dataerror }, jsonrequestbehavior.allowget); } 

and here razor view:

<a href="@url.action("hide", "mail", new {id = a.id})" id="hide" title="hide e-mail" class="btn btn-warning"><i class="glyphicon glyphicon-eye-close"></i></a> 

and jquery:

$("#hide").on("click", function () {     $.ajax({         type: "post",         url: $(this).attr("href"),         datatype: "json",         data: {},         success: function (data) {             if (data.issuccess === true) {                 $("div.alert-success").removeclass("hidden");                 settimeout(function () {                     $("div.alert-success").addclass("hidden");                 }, 5000);                 window.location.reload();             } else {                 $("#error").text(data.dataerror);                 $("div.alert-warning").removeclass("hidden");                 settimeout(function () {                     $("div.alert-warning").addclass("hidden");                 }, 5000);             }         },         error: function (request, status, error) {             alert(request.responsetext);         }     });     return false; }); 

you searching element called #hide, need ensure element exist when jquery event fired.

if element doesn't exist, jquery ajax wont work.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -