-2

I just need to request the src attribut image on a website. The source changes around 2 times every 10 minutes, so i can't paste the link's image. It's been a long time i'm looking for but nothing.

There is my code :

function loadPicture() {
            $.ajax({
            type: 'POST',
            url: 'https://myAdress.com',
            success: function(picture) {
              $('#picture').attr('src', picture); },
            error: function() {
              $('#picture').text('Une erreur est                            survenue.'); },
          });
        }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Thanks

2 Answers2

0

Set timeout for 3 seconds and load function again and again:

function loadPicture() {
            $.ajax({
            type: 'POST',
            url: 'https://myAdress.com',
            success: function(picture) {
              $('#picture').attr('src', picture); },
            error: function() {
              $('#picture').text('Une erreur est                            survenue.'); },
          });
        setTimeout(function(){loadPicture();},180000);//180 seconds
        }
     loadPicture();
Ritesh Khandekar
  • 3,885
  • 3
  • 15
  • 30
3.142857
  • 46
  • 5
0

Nice ! I found how to just request the src image. I had to assign my parameter with .attr('src') to a new variable.

type: 'POST',
url: 'https://myAdress.com',
success: function(picture) {
var myPicture = $(picture).attr('src'); },