Answer the question
In order to leave comments, you need to log in
How to get the following records in ajax request?
I'm trying to do ajax upload of articles.
public function index(Request $request) {
$tasks = Task::paginate(5);
if($request->ajax()){
$tasks = Task::take(5)->offset(5)->limit(5)->get();
$response="";
foreach ($tasks as $task){
$response.="
<div class='card'>
<div class='card-content'>
<span class='card-title activator grey-text text-darken-4'>$task->title<i class='material-icons right'>more_vert</i></span>
<p><a href=\"#\">This is a link</a></p>
</div>
<div class='card-reveal'>
<span class='card-title grey-text text-darken-4'>$task->title<i class='material-icons right'>close</i></span>
<p>$task->text</p>
</div>
</div>";
}
return $response;
}else {
return view('home', ['tasks' => $tasks]);
}
}
@extends('layouts.app')
@section('title', 'Master')
@section('content')
<div id="tasks">
@foreach ($tasks as $task)
<div class="card">
<div class="card-content">
<span class="card-title activator grey-text text-darken-4">{{$task->title}}<i class="material-icons right">more_vert</i></span>
<p><a href="#">This is a link</a></p>
</div>
<div class="card-reveal">
<span class="card-title grey-text text-darken-4">{{$task->title}}<i class="material-icons right">close</i></span>
<p>{{$task->text}}</p>
</div>
</div>
@endforeach
</div>
<center><a class="waves-effect waves-light btn" id="load-more">Load more</a></center>
@endsection
$( document ).ready(function() {
$("#load-more").click(function () {
console.log("load more");
$.get(
"/tasks",
{
param1: "param1",
},
onAjaxSuccess
);
function onAjaxSuccess(data)
{
console.log(data);
}
})
});
Answer the question
In order to leave comments, you need to log in
$("#load-more").click(function () {
offset+=20;
controller:
$tasks = Task::take(20)->offset($request->query('offset'))->limit (20)->get();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question