Answer the question
In order to leave comments, you need to log in
How to make an AJAX request on one page and get the result on another?
I use AJAX (JSON data type) and Laravel.
Wrote an AJAX request that gets a new record of the current feed:
var myJsonData = {
"_token": "{{ csrf_token() }}",
id: '{{ $feed->id }}'
};
$.post(
'{{ route("feed-get-mess", $feed->id) }}',
myJsonData,
function(response) {
$('#AjaxGetMessages').append(response.message);
console.log(response);
}
);
public function ajax_mess(Request $request)
{
$feed_ajax = Feed::findOrFail($request->id);
$messages_ajax = $feed_ajax->messages()->latest()->first();
return $messages_ajax;
}
Answer the question
In order to leave comments, you need to log in
How to make an AJAX request on one page and get the result on another?
function fetchdata(){
$.ajax({
url: 'fetch_details.php',
type: 'get',
success: function(response){
// Perform operation on the return value
alert(response);
}
});
}
$(document).ready(function(){
setInterval(fetchdata,5000);
});
function fetchdata(){
$.ajax({
url: 'fetch_details.php',
type: 'get',
success: function(data){
// Perform operation on return value
alert(data);
},
complete:function(data){
setTimeout(fetchdata,5000);
}
});
}
$(document).ready(function(){
setTimeout(fetchdata,5000);
});
$.post(
'{{ route("feed-get-mess", $feed->id) }}',
myJsonData,
function(response) {
$('#AjaxGetMessages').append(response.message);
console.log(response);
}
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question