Re-run javascript?


Don’t understand how to do that…

I have two pages, A and B.
On page A I have different buttons. One button is “highlighted”, which one it has to be is done via a ajax post request (mysql)

When I change to page B and go back to page a, the ajax request is not made again.
But I want the buttons to update, so the ajax request should be called again.

How can I do that??



You probably do your ajax request in the pageInit event handler, which is only done once for each page. If you want to run your code every time the page is displayed, put it in pageBeforeIn event handler.

1 Like

Thank you for your answer.

I tried that, but no code is executed at all… I added the js code at the end of the body.

$$(document).on('page:beforein', function (e) {

var insertFile = "db/screen_mode_db.php";

  //ajax request
  $.post(insertFile, {action: "check"},

  if (data != "") {

    //set switch


Have I misunderstood something?

Thank you!

What happens is: the script in the “page:beforein” tag is executed only the second/third/… time the page is loaded and not the first time.

page:init is not doing anything.

How can I use the same code to be executed always?

Thank you!