Ajax returns error after modifying htaccess

3

I've modified the .htaccess with a rule for the url to be passed as a GET parameter and I treat everything in index.php :

Options +FollowSymLinks

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ index.php?params=$1 [QSA]

After this change, ajax (post) below returns as an error and does not complete my request:

$("#criar").click(function()
    {
        $.ajax
       ({
            type : 'post',
            url : "http://www.xxxx.com.br/criar-pagina-ajax.php",
            data: 
            {
                nomepagina: $('#nome-pagina').val(),
                idcategoria: $('#id-categoria').val(),
                idpaginacurtir: $('#id-pagina-curtir').val(),
                youtube: getYoutubeId($('#youtube').val()) 
            },
            dataType : "json",
            beforeSend : function()
            {
                $("#mensagem").html('Verificando...');
            },
            success : function(data)
            {
                $("#mensagem").html(data.mensagem);
                if (data.cod == 1)
                {
                    location.reload();
                }
            }
        })
    });

I can not solve this problem, I believe the URL is being rewritten with the .htaccess rule and POST is not recognized in criar-pagina-ajax.php .

    
asked by anonymous 27.02.2014 / 23:27

1 answer

2

Yes, the problem in this case is the URL. I see how to change your URL:

From: http://www.xxxx.com.br/criar-pagina-ajax.php

To: http://www.xxxx.com.br/criar-pagina

So when you split your URL you're picking up the variable $_GET['params'] in index.php you'll see that the request is to create the page, and you can call the function that is written in the script criar-pagina-ajax.php

EDIT
A basic example of index.php :

$requisicao = explode("/", $_GET['params']);
$parametro = $requisicao[count($requisicao) - 1]; // $parametro = "criar-pagina"
if ($parametro == "criar-pagina") {
    // Faça alguma coisa
}
    
27.02.2014 / 23:32