简体   繁体   中英

Show Success message is not Working in JavaScript

$.ajax({ 
     type: "POST",
     url:'/saveLayout',          
     data: {id : layoutId, section :  arrSection},
     success: function(response){  
               $('#successMsg').addClass("errorBox");
               document.getElementById('successMsg').innerHTML="Your data has been successfully          saved.";
              }
    });

Show success message in ajax success function is not working in second time in Crome.
The success message works at first time. But its not working after that.

Your code is reusing the same HTML block to display the success message, so the second message will simply replace the first. If you want it to display two success messages at the same time, then you will need to append the message. Is that the problem?

Here is an example of appending the message:

$.ajax({
    type: "POST",
    url:'/saveLayout',
    data: {
        id : layoutId,
        section : arrSection
    },
    success: function(response) {
        $("#successMsg").addClass("errorBox").append("Your data has been successfully saved.");
    }
});

I think you need to remove the errorbox class before add.

$('#successMsg').removeClass("errorBox"); 
$('#successMsg').addClass("errorBox"); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM