0

The data from ajax (json) is fine and up to date, but the data shown in my modal is the one from the first page load. The data in "console.log" ist correct. Seems to be a chache issue?

$('.showCallhistory').click(function(e) {
        var callsId = $(this).data("id");
        $.ajax({
            cache: false,
            url : '?eID=ajaxDispatcher&callId='+callsId,
            dataType : 'json',
            success : function(data) {
                var callhistoryhtml = '';
                callhistoryhtml +='<div class="well"><dl class="dl-horizontal">';
                $.each(data, function(i, val) {
                    callhistoryhtml += '<dt>'+val.chCrdate+'</dt><dd>'+val.chEntry+' | durch: '+val.feUsername+'</dd>';
                    console.log(val.chEntry + ' : ' + val.chCrdate+ ' : ' + val.feUsername);
                });
                callhistoryhtml += '</dl></div>';
                $('.replaceMe').replaceWith(callhistoryhtml);
                $('#myModal').modal('toggle');
            },
            error : function(result) {
                alert('error ' + result.myResult);
            },
        });
    });

my modal, in which the content is not properly replaced:

    <div class="modal fade" id="myModal" tabindex="-1" role="dialog"
    aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"
                    aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">Call-Historie</h4>
            </div>
            <div class="modal-body replaceMe">...</div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">schliessen</button>
            </div>
        </div>
    </div>
</div>
metaxos
  • 151
  • 1
  • 16
  • just realized that the problem is the $('.replaceMe').replaceWith(callhistoryhtml); i use now $('.replaceMe').empty(); $('.replaceMe').append(callhistoryhtml); and this works as whished – metaxos Feb 28 '14 at 14:51

1 Answers1

0

The problem was the:

$('.replaceMe').replaceWith(callhistoryhtml);

Now using following instead and this brings the needed effect:

$('.replaceMe').empty();
$('.replaceMe').append(callhistoryhtml);

Are there any comments/better ways?

metaxos
  • 151
  • 1
  • 16