javascript - Submit button stops to work after adding ajax call in Laravel
Get the solution ↓↓↓I've a contact form. If I define route in action, it redirects user to a proper route. But I want to handle this form with Ajax not with simple loading of page.
After writing jQuery code for ajax call, my submit button has stopped to work. Onclick, it does nothing.
I need to know what I' m doing wrong and how would I treat it with ajax call?
Blade
<form method="post "action="javascript:void(0)" id="updateprofile" enctype="multipart/form-data">
@csrf
<input type="text" id="name" name="name">
<input type="email" id="email" name="email">
<input type="hidden" id="zoom" value="$user->zoom">
<input type="hidden" id="is_submitted_firsttime" value="$user->is_submitted_firsttime">
<button type="submit" class="btn btn-primary" id="submitbtn">Submit</button>
<button type="button" id="myaccount_edit" class="btn">Edit</button>
</form>
Javascript
$("#updateprofile").validate({
rules: {
name:"required",
email:"required",
},
submitHandler: function () {
$("#location").keyup(function(event){
if(event.keyCode == 13) {
event.preventDefault();
$('#submitbtn').addClass('testing')
}
else{
$('#submitbtn').removeClass('testing')
}
});
if (!$('#submitbtn').hasClass("testing")) {
var serializeData = $('#updateprofile').serialize();
$.ajax({
url: "{{ route('myaccount.ajax_store') }}",
data: serializeData,
dataType: 'json',
contentType: false,
cache: false,
processData:false,
success: function(response){
if(response==true){
$('#company-logo').attr('disabled','disabled');
}
else{
setTimeout(function() {
toastr.options = {
closeButton: true,
progressBar: true,
showMethod: 'slideDown',
timeOut: 4000
};
toastr.error('Something went wrong!');
}, 1300);
}
}
});
}
}
});
Controller
class ProfileController extends Controller
{
function ajax_store(Request $request)
{
dd(1);
}
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: cannot use isset() on the result of an expression (you can use "null !== expression" instead)
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.