Using AJAX with Laravel GET request not working
up vote
0
down vote
favorite
What I am trying to do is to load @yield('somecontent.content')
on a master a master layout dynamically. Just for informative purposes I have the following:
Controller:
public function someFunction()
{
//DB logic here
return view('/exampleView')
->with($dataset1)
->with($dataset2)
->with($dataset3)
->with($dataset4);
}
Route:
Route::get('someRoute', ['as' => 'theRoute', 'uses' => 'someController@someFunction']);
Ajax/jquery function:
$(document).ready(function(){
$('.ajaxClick').click(function(event){
//event.preventDefault();
$.ajax(
type: 'GET',
url: 'theRoute',
datatype: 'json',
success: function(data){
console.log('AJAX loaded something');
},
error: function(){
console.log('AJAX load did not work');
}
});
});
});
View logic:
<a class="ajaxClick" data-name="{{
route('theRoute') }}" href="#">Testing Ajax</a>
In the a tag I had the route originally which would work but would refresh the page and not load without refreshing.
How it flows is, click the link in the navbar and load the Laravel route dynamically in a set field which is allocated for views to load in by using @yield('somecontent')
.
Also another question would be, how would you implement this in Laravel? If need anything else comment.
Thankyou!
P.S
This example of a dashboard is pretty much what I want to do, how the content loads straight away without any refreshing of the page.
jquery ajax laravel laravel-5
add a comment |
up vote
0
down vote
favorite
What I am trying to do is to load @yield('somecontent.content')
on a master a master layout dynamically. Just for informative purposes I have the following:
Controller:
public function someFunction()
{
//DB logic here
return view('/exampleView')
->with($dataset1)
->with($dataset2)
->with($dataset3)
->with($dataset4);
}
Route:
Route::get('someRoute', ['as' => 'theRoute', 'uses' => 'someController@someFunction']);
Ajax/jquery function:
$(document).ready(function(){
$('.ajaxClick').click(function(event){
//event.preventDefault();
$.ajax(
type: 'GET',
url: 'theRoute',
datatype: 'json',
success: function(data){
console.log('AJAX loaded something');
},
error: function(){
console.log('AJAX load did not work');
}
});
});
});
View logic:
<a class="ajaxClick" data-name="{{
route('theRoute') }}" href="#">Testing Ajax</a>
In the a tag I had the route originally which would work but would refresh the page and not load without refreshing.
How it flows is, click the link in the navbar and load the Laravel route dynamically in a set field which is allocated for views to load in by using @yield('somecontent')
.
Also another question would be, how would you implement this in Laravel? If need anything else comment.
Thankyou!
P.S
This example of a dashboard is pretty much what I want to do, how the content loads straight away without any refreshing of the page.
jquery ajax laravel laravel-5
What does your browser console say? Also check the Network tab. FYI, it'sdataType
, notdatatype
(case is important). Also, the error callback has information passed to it which you can use. For example ~error: (jqXhr, status, error) => { console.error(status, error) }
– Phil
Nov 13 at 3:52
Another issue, your response must be JSON. Otherwise it will fail.
– itachi
Nov 13 at 3:54
@itachi actually, with the incorrectdatatype
, it won't matter 🙂
– Phil
Nov 13 at 3:54
yeah. Agreed. It shouldn't matter as of now.
– itachi
Nov 13 at 3:55
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
What I am trying to do is to load @yield('somecontent.content')
on a master a master layout dynamically. Just for informative purposes I have the following:
Controller:
public function someFunction()
{
//DB logic here
return view('/exampleView')
->with($dataset1)
->with($dataset2)
->with($dataset3)
->with($dataset4);
}
Route:
Route::get('someRoute', ['as' => 'theRoute', 'uses' => 'someController@someFunction']);
Ajax/jquery function:
$(document).ready(function(){
$('.ajaxClick').click(function(event){
//event.preventDefault();
$.ajax(
type: 'GET',
url: 'theRoute',
datatype: 'json',
success: function(data){
console.log('AJAX loaded something');
},
error: function(){
console.log('AJAX load did not work');
}
});
});
});
View logic:
<a class="ajaxClick" data-name="{{
route('theRoute') }}" href="#">Testing Ajax</a>
In the a tag I had the route originally which would work but would refresh the page and not load without refreshing.
How it flows is, click the link in the navbar and load the Laravel route dynamically in a set field which is allocated for views to load in by using @yield('somecontent')
.
Also another question would be, how would you implement this in Laravel? If need anything else comment.
Thankyou!
P.S
This example of a dashboard is pretty much what I want to do, how the content loads straight away without any refreshing of the page.
jquery ajax laravel laravel-5
What I am trying to do is to load @yield('somecontent.content')
on a master a master layout dynamically. Just for informative purposes I have the following:
Controller:
public function someFunction()
{
//DB logic here
return view('/exampleView')
->with($dataset1)
->with($dataset2)
->with($dataset3)
->with($dataset4);
}
Route:
Route::get('someRoute', ['as' => 'theRoute', 'uses' => 'someController@someFunction']);
Ajax/jquery function:
$(document).ready(function(){
$('.ajaxClick').click(function(event){
//event.preventDefault();
$.ajax(
type: 'GET',
url: 'theRoute',
datatype: 'json',
success: function(data){
console.log('AJAX loaded something');
},
error: function(){
console.log('AJAX load did not work');
}
});
});
});
View logic:
<a class="ajaxClick" data-name="{{
route('theRoute') }}" href="#">Testing Ajax</a>
In the a tag I had the route originally which would work but would refresh the page and not load without refreshing.
How it flows is, click the link in the navbar and load the Laravel route dynamically in a set field which is allocated for views to load in by using @yield('somecontent')
.
Also another question would be, how would you implement this in Laravel? If need anything else comment.
Thankyou!
P.S
This example of a dashboard is pretty much what I want to do, how the content loads straight away without any refreshing of the page.
jquery ajax laravel laravel-5
jquery ajax laravel laravel-5
edited Nov 13 at 3:49
asked Nov 13 at 3:10
IneedToAskQuestions
145
145
What does your browser console say? Also check the Network tab. FYI, it'sdataType
, notdatatype
(case is important). Also, the error callback has information passed to it which you can use. For example ~error: (jqXhr, status, error) => { console.error(status, error) }
– Phil
Nov 13 at 3:52
Another issue, your response must be JSON. Otherwise it will fail.
– itachi
Nov 13 at 3:54
@itachi actually, with the incorrectdatatype
, it won't matter 🙂
– Phil
Nov 13 at 3:54
yeah. Agreed. It shouldn't matter as of now.
– itachi
Nov 13 at 3:55
add a comment |
What does your browser console say? Also check the Network tab. FYI, it'sdataType
, notdatatype
(case is important). Also, the error callback has information passed to it which you can use. For example ~error: (jqXhr, status, error) => { console.error(status, error) }
– Phil
Nov 13 at 3:52
Another issue, your response must be JSON. Otherwise it will fail.
– itachi
Nov 13 at 3:54
@itachi actually, with the incorrectdatatype
, it won't matter 🙂
– Phil
Nov 13 at 3:54
yeah. Agreed. It shouldn't matter as of now.
– itachi
Nov 13 at 3:55
What does your browser console say? Also check the Network tab. FYI, it's
dataType
, not datatype
(case is important). Also, the error callback has information passed to it which you can use. For example ~ error: (jqXhr, status, error) => { console.error(status, error) }
– Phil
Nov 13 at 3:52
What does your browser console say? Also check the Network tab. FYI, it's
dataType
, not datatype
(case is important). Also, the error callback has information passed to it which you can use. For example ~ error: (jqXhr, status, error) => { console.error(status, error) }
– Phil
Nov 13 at 3:52
Another issue, your response must be JSON. Otherwise it will fail.
– itachi
Nov 13 at 3:54
Another issue, your response must be JSON. Otherwise it will fail.
– itachi
Nov 13 at 3:54
@itachi actually, with the incorrect
datatype
, it won't matter 🙂– Phil
Nov 13 at 3:54
@itachi actually, with the incorrect
datatype
, it won't matter 🙂– Phil
Nov 13 at 3:54
yeah. Agreed. It shouldn't matter as of now.
– itachi
Nov 13 at 3:55
yeah. Agreed. It shouldn't matter as of now.
– itachi
Nov 13 at 3:55
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
if you still want to use jQuery, you can use something like this:
$(document).ready(function(){
$('.ajaxClick').click(function(event){
//event.preventDefault();
$.ajax({
type: 'GET',
url: 'theRoute',
datatype: 'json',
success: function(data){
$('#main-wrapper').html(data);
},
error: function(){
console.log('AJAX load did not work');
}
});
});
});
I suggest you try and study javascript frameworks. The link you sent is using Angular JS, and the functionalities you need are built into them, and is called SPA or Single Page Application
Uncomplete list of JS Framework:
- Angular
- React
- Vue
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
if you still want to use jQuery, you can use something like this:
$(document).ready(function(){
$('.ajaxClick').click(function(event){
//event.preventDefault();
$.ajax({
type: 'GET',
url: 'theRoute',
datatype: 'json',
success: function(data){
$('#main-wrapper').html(data);
},
error: function(){
console.log('AJAX load did not work');
}
});
});
});
I suggest you try and study javascript frameworks. The link you sent is using Angular JS, and the functionalities you need are built into them, and is called SPA or Single Page Application
Uncomplete list of JS Framework:
- Angular
- React
- Vue
add a comment |
up vote
0
down vote
accepted
if you still want to use jQuery, you can use something like this:
$(document).ready(function(){
$('.ajaxClick').click(function(event){
//event.preventDefault();
$.ajax({
type: 'GET',
url: 'theRoute',
datatype: 'json',
success: function(data){
$('#main-wrapper').html(data);
},
error: function(){
console.log('AJAX load did not work');
}
});
});
});
I suggest you try and study javascript frameworks. The link you sent is using Angular JS, and the functionalities you need are built into them, and is called SPA or Single Page Application
Uncomplete list of JS Framework:
- Angular
- React
- Vue
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
if you still want to use jQuery, you can use something like this:
$(document).ready(function(){
$('.ajaxClick').click(function(event){
//event.preventDefault();
$.ajax({
type: 'GET',
url: 'theRoute',
datatype: 'json',
success: function(data){
$('#main-wrapper').html(data);
},
error: function(){
console.log('AJAX load did not work');
}
});
});
});
I suggest you try and study javascript frameworks. The link you sent is using Angular JS, and the functionalities you need are built into them, and is called SPA or Single Page Application
Uncomplete list of JS Framework:
- Angular
- React
- Vue
if you still want to use jQuery, you can use something like this:
$(document).ready(function(){
$('.ajaxClick').click(function(event){
//event.preventDefault();
$.ajax({
type: 'GET',
url: 'theRoute',
datatype: 'json',
success: function(data){
$('#main-wrapper').html(data);
},
error: function(){
console.log('AJAX load did not work');
}
});
});
});
I suggest you try and study javascript frameworks. The link you sent is using Angular JS, and the functionalities you need are built into them, and is called SPA or Single Page Application
Uncomplete list of JS Framework:
- Angular
- React
- Vue
answered Nov 13 at 4:00
Joe
322217
322217
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273219%2fusing-ajax-with-laravel-get-request-not-working%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What does your browser console say? Also check the Network tab. FYI, it's
dataType
, notdatatype
(case is important). Also, the error callback has information passed to it which you can use. For example ~error: (jqXhr, status, error) => { console.error(status, error) }
– Phil
Nov 13 at 3:52
Another issue, your response must be JSON. Otherwise it will fail.
– itachi
Nov 13 at 3:54
@itachi actually, with the incorrect
datatype
, it won't matter 🙂– Phil
Nov 13 at 3:54
yeah. Agreed. It shouldn't matter as of now.
– itachi
Nov 13 at 3:55