Level 75
Aug 15, 2017
1
Level 1
TokenMismatchException in VerifyCsrfToken.php
Hello guys. I have a problem with my ajax POST request.
my head tah:
<meta name="csrf-token" content="{{ csrf_token() }}">
Here is my form:
<form id="contentForm" action="/faq" method="POST">
{{csrf_field()}}
<colgroup>
<col width="20%" /><col width="80%" />
</colgroup>
<tbody>
<tr class="Field">
<th align="right" scope="row">First Name:*</th>
<td>
<input type="text" class="textbox-big" tabindex="2" id="FirstName" maxlength="400" name="FirstName" required style="width: 200px" />
</td>
</tr>
<tr class="Field">
<th align="right" scope="row">Email Address:*</th>
<td>
<input type="text" required class="textbox-big" tabindex="9" id="EmailAddress" size="26" maxlength="100" name="EmailAddress" required style="width: 200px" />
<span class="hidden" id="js-email-validate" style="color: red">Please enter a valid Email.</span>
</td>
</tr>
<tr class="Field">
<th align="right" scope="row">Subject:*<br /></th>
<td>
<input type="text" class="textbox-big" tabindex="11" required="" id="Subject" maxlength="400" name="Subject" required style="width: 200px" />
</td>
</tr>
<tr class="Field">
<th align="right" scope="row">Message:<br /></th>
<td>
<textarea class="textbox-multiline" tabindex="12" id="Comments" cols="60" rows="4" name="Comments" required></textarea>
</td>
</tr>
<tr>
<td> </td>
<td align="left" scope="row">
<div id="contact-us-buttons">
<input type="submit" class="button-action" tabindex="14" id="ContactUsSubmitButton" value="Submit" name="" />
</div>
</td>
</tr>
</tbody>
</form>
Here is my ajax:
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$(document).ready(function(){
$('#ContactUsSubmitButton').on('click',function(e){
e.preventDefault();
var FirstName = $('#FirstName').val().trim();
var EmailAddress = $('#EmailAddress').val().trim();
var Subject=$('#Subject').val().trim();
var Message=$('#Comments').val().trim();
if (FirstName.length==0 || EmailAddress.length==0 || Subject.length==0 || Message.length==0 ) {alert('Заполните все');}else{
$.ajax({
url:"/faq",
method:"POST",
dataType: "json",
data: {
'FirstName' : FirstName,
'EmailAddress' : EmailAddress,
'Subject' : Subject,
'Message' : Message
},
success:function(data){
alert(data);
},
cache: false,
contentType: false,
processData: false
});
}
});
});
Please or to participate in this conversation.