view
==========
$('#searchstudent').on('click',function(){
event.preventDefault();
var formdata = $('#searchform').serialize();
console.log(formdata);
$.ajax({
url:'/test',
type:'post',
dataType:'json',
data : formdata ,
success : function(data){
console.log('hey'+data);
}
});
});
route
Route::post('/test', ['as'=>'test','uses'=>'HomeController@test']);
controller
use Illuminate\Http\Response;
public function test(Request $request){
return response()->json(['name' => 'praveen', 'country' => 'SL']);
}
Issues I Face
1)Currently i am in this url
http://localhost/blog/allocatestudent/1
from this url only my view is rendered and from here i am calling above mentioned ajax function
Error message i got from console
POST http://localhost/test 404 (Not Found)
What i tried to change the url in ajax function like below
url:'test' instead of url:'/test'
and in my route
Route::post('test', ['as'=>'test','uses'=>'HomeController@test']);
so i am getting another error message as
POST http://localhost/blog/allocatestudent/test 405 (Method Not Allowed)
Anybody can tell me where i am doing wrong?...