Javascript从AJAX if-loop更改CSS类背景图像

I have this CSS:

.modal-content {
    max-height: 370px;
    background-image: url('../images/img_before_submit.png');
}

And I am having a php-mail script that will respond with and "ok" for a successful mail sending or "bad" for an error.

I am using a AJAX script for mail handling:

              success:function(response) {

                      if(response == 'ok') { 
                        $('.modal-content').css('background-image', 'url(images/success.png)');
                        sleep(2000); 
                        alert(response);
                      } else {
                        $('.modal-content').css('background-image', 'url(images/error.png)')
                        sleep(2000); 
                        alert(response);
                      } 
}

From the console and outside the if-loop in the AJAX this code work as expected:

$('.modal-content').css('background-image', 'url(images/img.png)');

But inside the AJAX if-loop this code does not apply, but the correct alert msg response is coming through and is showing up! How can I set the background-image from within the if-loop?