How to change AJAX response HTML and then continue replacemant in jQuery?

386
November 22, 2016, at 10:47 AM

I have an AJAX that gets new HTML and replaces the form data in response.html. There is one attribute that I need changed before the replacement.

Here is my try but I cant get it right:

success: function(response, status, xhr) {
    if (response.data.html !== null) {
        var newdata = response.data.html;
        if(firstload == 1){
            var newhtml  = $(newdata).find('.trigger').attr('data-firstload',0);
            // now I need to replace newdata
        }
        $(container).html(newdata); 
    }
}
Answer 1

You can create a jQuery object containing the new HTML, update it, then append it. Try this:

success: function(response, status, xhr) {
    if (response.data.html !== null) {
        var $newHtml = $(response.data.html);
        if (firstload == 1)
            $newHtml.find('.trigger').attr('data-firstload', 0);
        $(container).empty().append($newHtml);
    }
},
READ ALSO
Bootstrap Check Box Binding With Knockout Freezed

Bootstrap Check Box Binding With Knockout Freezed

Bootstrap http://wrapbootstrap. com/preview/WB0135486.

278
Wordpress modal login works but default login submit not working any more

Wordpress modal login works but default login submit not working any more

Im creating a modal wordpress login using the leanmodal js, I figuret it out the form is working fine but I have a problem with the default login. .

320
Json reader issue

Json reader issue

When I used localhost:8080/SpringServiceJsonSample/rest/service/user/ on browser I return all data in json type, but when I used this url in jquery grid data is not loaded, I have also used debugger, but there is no error I got. .

391