من کد زیر را نوشته ام اما نمی دانم چرا ajax دوم کار نمیکند کدم را چگونه باید تغییر بدهم
<h2>Index</h2> <p> <a class="btn btn-primary" onclick="Create();">افزودن شخص جدید</a> </p> <div id="list"> @Html.Action("List") </div> <!-- Modal --> <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <h5 class="modal-title" id="exampleModalLabel">Modal title</h5> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> </div> <div class="modal-body" id="bodyModal"> ... </div> <div class="modal-footer"> <button type="button" class="btn btn-default" id="close">Close</button> <button type="button" class="btn btn-primary" id="editaaaa">Save changes</button> </div> </div> </div> </div> @section scripts { <script> function Create() { $.ajax({ url: '@Url.Action("Create", "TestModals")', type: "Get", data: {} }).done(function (res) { $("#exampleModal").modal("show"); $("#exampleModalLabel").html('افزودن'); $("#bodyModal").html(res); }); } </script> <script> $(function () { $("#editaaaa").on('click', function () { // debugger; var dataObject = { Name: $("#Name").val(), Family: $("#Family").val(), Age: $("#Age").val(), CreateDate: $("#CreateDate").val() }; $.ajax({ url: '@Url.Action("Create", "TestModals")', type: "POST", data: dataObject, dataType: "json", success: function (data) { if (data.toString() == "True") { debugger; $("#exampleModal").modal('hide'); $.ajax({ url: '@Url.Action("list", "TestModals")', type: "Get", data: {}, dataType: "json", success: function (data) { $('#list').html(data); } }); } else { console.log(2); } }, error: function () { console.log(Error.message); } }); }); }); </script> }
باتشکر
لاگ کنسسول مروگر را بررسی کنید و اگر خطا داره برطرف کنید
سلام
لاک کنسول هیچ خطای نداره
نمونه کدی ندارید مهندس قرار بدهید
کد دوم را function کنید و در کد اول صدا بزنید
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)