How to run a PHP script without refresh with jQuery?

Asked

Viewed 1,295 times

0

If you access this site GCMC Advocacia You may notice that the menu will only change language if you double-click the flag. This is because the page is not running the script that loads the menu according to the language of the first time. I imagine it’s something related to jQuery and AJAX, but I don’t have enough experience to do the script. Can you please help me?

I’m using this PHP code:

$en = explode("/", $_SERVER['HTTP_REFERER']); $idioma = $en[4];

It is he who changes the language by popping the url and detecting if the string '/en/' is found in the url as soon as the menu changes language. I need to run the PHP script really every refresh allowing immediate menu exchange.

  • 1

    This information is not enough for someone to help you. Why do you think it is related to Ajax and/or jQuery? The language links look like common links, which do not use ajax. You may have a logic problem in your PHP (generating the menu before resetting the language).

  • This question is the same as this http://answall.com/questions/6299/load-post-sem-refresh-da-pagina-com-ajax-e-jquery?

2 answers

2


Try to change $_SERVER['HTTP_REFERER'] for $_SERVER['REQUEST_URI'];.

$_SERVER['HTTP_REFERER'] is the variable that stores the address of the page that sent the user to the current page, so it works on the second click.

  • Congratulations "IGROSSITER" for simply trying to help !!!

  • vlw, we are there! ^^

1

AJAX with jQuery is extremely simple, follow an example:

$.ajax({
  url: "teste.html",
  cache: false
})
  .done(function( html ) {
    $( "#resultados" ).append( html ); // Ou qualquer outra comando com o resultado que é 'html'
  });

Unfortunately I can not solve your problem specifically, take a read on Javascript and jQuery, which will be very easy if you already program in some language.

Some links:

Javascript Tutorial

Medical centers in W3schools

  • Ok, but with the information we have it is not even possible to tell if the problem has to do with ajax or jQuery...

  • I fully agree

Browser other questions tagged

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