Skip to content Skip to sidebar Skip to footer

Javascript Stop Working After Ajax Call

My javascript is getting locked after ajax call. When the user press enter then i call my c# method to search the city that the user typed, and then show the temperature, but when

Solution 1:

Try the following and see if it works for you:

 $(function () {
     var$searchbar = $('#search-bar'),
         $grid = $('#rb-grid');

     if ($grid.length) {
         $searchbar.on('keyup', function (event) {
             if (event.keyCode == 13) {
                 myFunction();

             }
         });

         functionmyFunction() {
             var city = $searchbar.val();
             $.ajax({
                 url: $.grid.data('weather-url'),
                 data: { city: city }
             })
             .done(function (resp) {
                     $grid.html(resp.responseText + $grid.html());
                     Boxgrid.init();
                 }
             });
         }
     }
 });

Add the following as a data attribute somewhere in your html, probably on your grid:

 <div id='rb-grid' data-weather-url='@Url.Action("getWeatherSearch", "Index")'></div>

Post a Comment for "Javascript Stop Working After Ajax Call"