Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

177
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!