$(".btn-submit").click(function(e){
//*********** get data from form fields */
var name = $(".name").val();
var password = $(".password").val();
});
STEP 5: send request to server using ajax
$(".btn-submit").click(function(e){
var name = $(".name").val();
var password = $(".password").val();
//************* send request to server using ajax */
$.ajax({
type:'POST',
url:"{ route('ajaxRequest.post') }",
success:function(data){
}
});
});
STEP 6: send data to server using ajax
$(".btn-submit").click(function(e){
var name = $(".name").val();
var password = $(".password").val();
$.ajax({
type:'POST',
url:"{ route('ajaxRequest.post') }",
//** send data to server */
data:{name:name, password:password},
success:function(data){
}
});
});
Note that data: parameter
STEP 7: send csrf token
$(".btn-submit").click(function(e){
var name = $(".name").val();
var password = $(".password").val();
$.ajax({
type:'POST',
url:"{ route('ajaxRequest.post') }",
//** send csrf-token to server */
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
data:{name:name, password:password},
success:function(data){
}
});
});