Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

179
Visualizações
Doesn't work AJAX in Laravel 5.4

could You, please, help me? My code is dorsn't work. JS alert 'succes' but it's no changes on page. Thank You

Route

Route::post('/more', 'IndexController@index');

jQuery

$('#moreBtn').click(function () {

    $.ajax({
        method: 'post',
        url: '/more',
        data: 'fas',
        async: true,
        success: function(){
            alert('succes');
        },
        error: function(data){
            console.log(data);
            alert("fail" + ' ' + this.data)
        },

    });
});

Controller

class IndexController extends Controller
{
public function index(Request $request)
{

    $count = 8;

    $videos = Video::leftJoin('users', 'videos.user_id', '=', 'users.id')
        ->select('users.id', 'users.name', 'videos.*')
        ->orderBy('created_at', 'desc')
        ->take($count)
        ->get();


    if ($request->ajax()) {
        $count += 4;

    }



    return view('welcome', array(
        'videos' => $videos
    ));
}

}

Like i said, it's return 'succes', like ajax is ok, but doesn't change my page.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Data is not changing , because you are not changing it. Your ajax should more like

$.ajax({
    method: 'post',
    url: '/more',
    data: 'fas',
    async: true,
    success: function(response){
        alert('succes');
        $('body').html(response) // or to the id/class you would like to change
    },
    error: function(data){
        console.log(data);
        alert("fail" + ' ' + this.data)
    },

});

And one more thing, when you are doing ajax post request it is a good practice too keep and pass the token with the dat

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda