javascript - Calling a function according to class in JQuery -
sorry question, need little code in jquery / javascript
i have code emulate button <a href=""></a>
code
<a href="@url.action("create", "tourist", new { id = model.id })" eventsid="@model.id" class="btn btn-primary newtourist"><i class="fa fa-plus"></i> add</a>
i need code call function in <script></script>
declaration
declaration
<script type="text/javascript" src="~/scripts/jquery-1.11.0.js"></script> <script type="text/javascript"> function clearerrors() { $('#msgerrornewtourist').html(''); $('#msgerror').html(''); } function writeerror(control, msg) { var err_msg = '<div class="alert-message error"><a class="close" href="#">×</a><p>' + msg + '</p></div>'; $('#' + control).html(err_msg); } $(document).ready(function () { $('.closemodal').live('click', function () { this.remove(); $('#modal-tourist').modal('hide'); }); $('#modal-tourist form').live('submit', function () { clearerrors(); $.post($(this).attr('action'), $(this).serialize(), function (data, status) { $('#modal-tourist').modal('hide'); $("#eventsdetailslist").html(data); }).error(function (error, status, a, b) { writeerror('msgerror', 'error processing request. please check errors , try again!'); $('.modal-body div.alert').html(error.responsetext); }); return false; }); function getrequest(url) { $.ajax({ url: url, context: document.body, success: function (data) { $('.modal-content p.body').html(data); $(this).addclass("done"); $('#modal-tourist').modal('show'); $('#name').focus(); }, error: function (err) { writeerror('msgerrornewtourist', err.responsetext); } }); } $('a.newtourist').live('click', function () { alert('ingreso'); clearerrors(); var id = $(this).attr("eventsid"); var url = '@url.content("~/tourist/create")/' + id; getrequest(url); return false; }); }); </script>
but doesn't work, code running in state , in moments put alert('working');
in entire body of script verify code charge , running...
sorry bad english, can me , show me error of code , why doesn't work call function
$('a.newtourist').live('click', function () { alert('ingreso'); clearerrors(); var id = $(this).attr("eventsid"); var url = '@url.content("~/tourist/create")/' + id; getrequest(url); return false; });
thanks stephen muecke , frank fajardo
i change <script></script>
, replace .live() .on() , code work perfectly, have other issue think open other post that... guys
<script type="text/javascript" src="~/scripts/jquery-2.1.4.js"></script> <script type="text/javascript"> function clearerrors() { $('#msgerrornewtourist').html(''); $('#alert').html(''); } function writeerror(control, msg) { var err_msg = '<div class="alert-message error"><a class="close" href="#">×</a><p>' + msg + '</p></div>'; $('#' + control).html(err_msg); } $(document).ready(function () { $('#modal-tourist form').on('submit', function () { if ($(this).valid()) { $.ajax({ url: '@url.action("create","tourist")', data: $(this).serialize(), success: function (result) { $('#modal-tourist').modal('hide'); $("#eventsdetailslist").html(result); }, failure: function (err) { writeerror('body', 'wrong data'); } }); } return false; }); function getrequest(url) { jquery.noconflict(); $.ajax({ url: url, context: document.body, success: function (data) { $('.modal-content p.body').html(data); $('#modal-tourist').modal('show'); $('#name').focus(); }, error: function (err) { writeerror('msgerrornewtourist', err.responsetext); } }); } $('a.newtourist').click(function () { var id = $(this).attr("eventsid"); var url = '@url.content("~/tourist/create")/' + id; getrequest(url); return false; }); }); </script>
Comments
Post a Comment