Using AJAX / jQuery to refresh an image

前端 未结 4 1267
生来不讨喜
生来不讨喜 2020-12-06 15:04

This is probably a simple question but I am stumped and just don\'t know where to start.

I have a PHP script (image_feed.php) that returns a URL to an image. Every t

4条回答
  •  一整个雨季
    2020-12-06 15:30

    Consider, if you have to fetch the URL again from the server, for a new image URL, you can do this way:

    $.ajax({
      url: 'getnewimageurl.php',
      success: function(data) {
        $('img').attr('src', data);
      }
    });
    

    The server should return only a new image name in it. For eg., the PHP code should be this way:

    
    

提交回复
热议问题