JQuery Mobile issue with AJAX update

I have a very strange problem with switches in jQuery Mobile. I fill some radio objects with ajax. When I do this for the first time, this is normal, but any subsequent loads seem to cause problems with the display - each flag is displayed separately, and not in the same list.

function getWords() {

    var gig_id = $('#gigs').val(); 

    $.ajax({
        url: Nnn.serverLocation+'/words?gigid='+ gig_id,
        success: function(data) {   
            Nnn.words =  eval('(' + data + ')');  
            displayWords();
        }
    });
}

function displayWords() {
    $('#word_container').html('<fieldset data-role="controlgroup" id="words"></fieldset>');

    $('#words').html("<legend>It's:</legend>");
    $.each(Nnn.words, function(key, value) { 
        $('#words').append('<label for="'+value.Word+'" >'+value.Word+'</label><input type="radio" value="'+value.Word+'" id="'+value.Word+'" name="radio-choice-1" />');           
    });

    $('#words input').checkboxradio();

    $('body').page();
}

HTML looks like

<div id='all' data-role="page">

    <div data-role="content">


    <div data-role="fieldcontain" id='word_container'>


        <fieldset data-role="controlgroup" id='words'>


        </fieldset>
     </div> 
      </div> 

It drives me crazy!

+3
source share
1 answer

The problem is loading / displaying CSS correctly on the page. If you reload the page using Ajax, you cannot use the HTML5 data attributes. For example, button controls in jQueryMobile are represented as follows:

<a href="index.html" data-role="button">Link button</a>

ajax, . , Firefox/Chrome/Opera- > Right Click- > Inspect Element . , :

<a class="ui-btn ui-btn-corner-all ui-shadow ui-btn-hover-c" data-role="button" href="index.html" data-theme="c">
  <span class="ui-btn-inner ui-btn-corner-all">
    <span class="ui-btn-text">Link button</span>
  </span>
</a>
+5

All Articles