OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Reload after click on button again in JQUERY

  • Thread starter Thread starter Maryam12 forex
  • Start date Start date
M

Maryam12 forex

Guest
This is my method:

Code:
      public async Task<IActionResult> GetAddNewAddressForm()
      {
          var state = await _siteService.GetStates();
          ViewData["State"] = state;

          var firstLocationId = state.First().LocationId;
          var district = await _siteService.GetDistricts(firstLocationId);
          ViewData["District"] = district;

          var model = new CartAddressViewModel();
          return PartialView("_AddNewAddressPartial", model);
      }

when i click on this button:

Code:
           <div class="row">
               <div class="col-lg-12">
                   <span class="font-weight-bold">

                       <button id="btnAddNewAddress" type="button" class="btn btn-primary" data-url="@Url.Action("GetAddNewAddressForm", "Home")">
                           <i class="fa fa-plus" aria-hidden="true"></i> Add New Address
                       </button>
                   </span>
               </div>
           </div>
           <div id="addNewAddressContainer">
           </div>

It works. this is my script:

Code:
       function bindAddNewAddressButton() {
           // Click event for adding new address
           $("#btnAddNewAddress").click(function () {
               var url = $(this).data("url");
               $.ajax({
                   url: url,
                   type: 'GET',
                   success: function (data) {
                       $("#addNewAddressContainer").empty().append(data);
                       // Bind change event for Location_Id in dynamically loaded form
                       $("#addNewAddressContainer").find("form:last #Location_Id").change(handleLocationChange);
                   },
                   error: function () {
                       alert('Error occurred while loading the form.');
                   }
               });
           });
       }

but for second click it does not work.
How can I handle for all clicking work? I try to handle with delegation but it works just one time and for second click I se this error:

Code:
       GET https://localhost:44371/YourController/GetAddNewAddressForm 404 (Not Found)

<p>This is my method:</p>
<pre><code> public async Task<IActionResult> GetAddNewAddressForm()
{
var state = await _siteService.GetStates();
ViewData["State"] = state;

var firstLocationId = state.First().LocationId;
var district = await _siteService.GetDistricts(firstLocationId);
ViewData["District"] = district;

var model = new CartAddressViewModel();
return PartialView("_AddNewAddressPartial", model);
}
</code></pre>
<p>when i click on this button:</p>
<pre><code> <div class="row">
<div class="col-lg-12">
<span class="font-weight-bold">

<button id="btnAddNewAddress" type="button" class="btn btn-primary" data-url="@Url.Action("GetAddNewAddressForm", "Home")">
<i class="fa fa-plus" aria-hidden="true"></i> Add New Address
</button>
</span>
</div>
</div>
<div id="addNewAddressContainer">
</div>
</code></pre>
<p>It works. this is my script:</p>
<pre><code> function bindAddNewAddressButton() {
// Click event for adding new address
$("#btnAddNewAddress").click(function () {
var url = $(this).data("url");
$.ajax({
url: url,
type: 'GET',
success: function (data) {
$("#addNewAddressContainer").empty().append(data);
// Bind change event for Location_Id in dynamically loaded form
$("#addNewAddressContainer").find("form:last #Location_Id").change(handleLocationChange);
},
error: function () {
alert('Error occurred while loading the form.');
}
});
});
}
</code></pre>
<p>but for second click it does not work.<br />
How can I handle for all clicking work? I try to handle with delegation but it works just one time and for second click I se this error:</p>
<pre><code> GET https://localhost:44371/YourController/GetAddNewAddressForm 404 (Not Found)
</code></pre>
 

Latest posts

Top