How to execute a function in ajax when opening the page?

Asked

Viewed 282 times

2

I have the following function in Ajax:

 $.ajax({
    type: "POST",
    url: "tra.php",
    data: {},
    dataType: 'json',
    suceess: function(Last)
    {
         line.originalData[0].push(Last);
         line.originalData[0].shift();

         RGraph.SVG.redraw();

    }
        });
    setTimeout(function () { update() }, 50);
}

 update();

However, the update() function is not starting, as I do for it to work?

  • Function in Ajax as soon as it loads? Usually it is better already in the first response of your site to provide this information. One less asynchronous call is a happy client plus and half the server load for your search model

2 answers

1


Try it this way:

$.ajax({
type: "POST",
url: "tra.php",
data: {},
dataType: 'json',
success: function(Last)
{
     line.originalData[0].push(Last);
     line.originalData[0].shift();

     RGraph.SVG.redraw();
     setTimeout(function () { update() }, 50);
}
    });

}

update();

0

The code snippet below is outside the function Success, and the function Success is spelled wrong.

setTimeout(function () { update() }, 50);}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.