recover url value without refresh

Asked

Viewed 125 times

0

I’m trying to recover the value of url for $_GET with php, I am absolutely sure it is impossible not to give refresh, something else as I would pass the title of each page also?

php

<?php
     if (isset($_GET['url'])) :

        $url = addslashes($_GET['url']);
        $sepURL = explode('/', $url);
        print_r($sepURL);

    endif;

    if (isset($_GET[$sepURL[0]])) :
        $lobby = $sepURL[0];
    endif;

    if (isset($lobby)) :
        require_once('lobby.php');
    else :
        require_once('private.php');
    endif;
?>

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ chat.php?url=$1

links

<li><a href="#" onclick="history.pushState('teste','Bem vindo','https://localhost/chat'); return false;">Geral</a></li>

<li><a href="#" onclick="history.pushState('teste','Amanda Caroline','https://localhost/chat/amanda-caroline'); return false;">Amanda Caroline</a></li>

he’s passing the right links, I’m just not getting their value back, someone has some idea?

  • You need to make an ajax call to the server

  • the more I pass on the ajax date?

  • I think nothing, since the data you need are in the url

  • man doesn’t have an example for a look?

  • Sopt is full of them just search, have with all kinds of library, framework or with pure JS

  • Sorry my ignorance, but what is it?

  • What is that? "Sopt" stands for STackTheverflow in portugues

Show 3 more comments

1 answer

1

If you just want to read the url you will need ajax, I use daily but never tried what you want to do, however it is possible, in my case I would use ajax not to give refresh and php to get the url, you can do as you wish, ajax would look like this

$(function(){
$('.DCSS').submit(function(){
    $.ajax({
        url: './func/dcss.func.php',
        type: 'POST',
        data: $('.DCSS').serialize(),
        success: function( data ){
            $('.aside').html(data);
        }
    });
    return false;
});

});

note that . DCSS is the class present in the tag and is also the name of the input Submit, the . aside is where the answer will come from, it would be a div to display the result or anywhere else, the url is the url of the file where it will read the url, it will probably set you up

<form class="DCSS" action="">
        <li><font class="mais">+</font> <input type="submit" value="<?php echo $DCSS ?> Desenvolvimento CSS" name='DCSS'> </li>
    </form>

A tip, do not use require_once unless it is necessary, if the file contains an error require_once or include_once will stop running the file and the page will turn white, it is better to use include

  • old only I have a problem with ajax every time q use url friendly it duplicates the page, I will edit this question

  • As it duplicates the page, it opens another tab?

  • for example, I have the <div id="wrapper">conteudo</div> when I use ajax and will make url friendly, every time I interact with something that uses ajax on the site, it displays twice the div wrapper, so I don’t like ajax, I’ve asked a question here about it, ngm knew the pq it happens

  • I really can’t understand how your Ajax does it, you probably missed some part of his logic, but without seeing his code it would be difficult to say, but this code I gave you works normal, I’m using now inclusive

Browser other questions tagged

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