javascript - Jquery keep class after ajax calls -


first important info. can't change in calls, code, functions etc used. bottomline have use workaround.

ok have form fields , dropdown. when loading form hide specific field jquery. field isw hidden when value matches value in array. problem i'm facing when use dropdown there's json call being made external service (for countries) , form being updated.

since can't code updates form after succesfull json call need find check if done loading , if hide specific field again.

to make things clear:

<div class="checkout-shipment-methods hidden">     <input id="eupack" name="shipment_method" value="eupack" type="radio">     <label for="eupack">delivered @ home</label>  </div>  <div class="checkout-shipment-methods">     <input id="pack" name="shipment_method" value="pack" type="radio">     <label for="pack">delivered @ work</label>  </div>       <select id="billing_address-country" name="billing_address[country]">    <option value="be" selected="selected">belgiƫ</option>    <option value="dk">denemarken</option>    <option value="de">duitsland</option> </select>       

input hidden now. when change select form updated , class hidden removed.

if change select there 2 calls made -> enter image description here

so thought check if calls made , if add class hidden again.

like so:

    $(function(){        var = [ 'fp32pe4','fp32le4' ];       var b = [ 'fp32pe1','fp32pe4' ];            $.each( a, function( key, value ) {             var index = $.inarray( value, b );             if( index != -1 ) {                var $id =  $('.checkout-shipment-methods:first-of-type');               $id.addclass('hidden');               localstorage.setitem("selectedolditem", $id);                    $.ajax({                     url: "url-to-link-in-image/nl/checkout/onestep/details/",                     beforesend: function( xhr ) {                         xhr.overridemimetype( "text/plain; charset=x-user-defined" );                     }                   }).                   then(function( data, textstatus, jqxhr ) {                     console.log('success');                        var selectedolditem = localstorage.getitem('selectedolditem');                        if (selectedolditem != null) {                          $('.checkout-shipment-methods:first-of-type').addclass("hidden");                         }                           },                        function( jqxhr, textstatus, errorthrown ) {                          console.log('fail')                    });             }         });       }); 

is possible?

ok,, can capture ajaxcomplete event,, triggers everytime ajax fired.. this:

$( document ).ajaxcomplete(function( event, xhr, settings ) {   if ( settings.url.indexof( "nl/service/regions/" ) != '-1' ) {      $('.checkout-shipment-methods:first-of-type').removeclass("hidden");   } }); 

and should work,, little expl:

  • we watching every ajax call webpage
  • if ajax call address like: /regions ..
  • if call captured, call removeclass on target elemeent

cheers, k


Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -