How to execute a PHP script without refresh with jQuery?

0

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

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 '/en/' string is in the url by doing so the menu changes language. I need to actually run the PHP script with every refresh, thus allowing immediate menu switching.

    
asked by anonymous 04.03.2014 / 19:33

2 answers

2

Try changing $_SERVER['HTTP_REFERER'] to $_SERVER['REQUEST_URI']; .

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

    
04.03.2014 / 22:21
1

AJAX with jQuery is extremely simple, here's 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, read about JavaScript and jQuery, which will be very easy if you already program in some language.

Some links:

Javascript Tutorial

jQuery in W3Schools

    
04.03.2014 / 20:14