What is failing? what is the issue?
Jul 15, 2023
20
Level 4
Issue with AJAX form submission using jQuery
I'm currently working on a web application that involves submitting a form using AJAX and jQuery. However, I'm facing difficulties in getting the form submission to work as expected. Here's my code:
<div class="form-group row">
<div class="col-lg-8">
<div class="d-flex align-items-center">
<h4 class="text-primary mr-2">DECISION:</h4>
<select class="form-control" id="decisionDropdown" name="decisionDropdown" onchange="toggleReasonDropdown()" >
<option value="OPTION">Please select</option>
<option value="APPROVE">APPROVE</option>
<option value="DECLINE">DECLINE</option>
</select>
</div>
</div>
</div>
</div>
</div>
<div class="col-xl-8 col-sm-8 border-right-1 prf-col">
<div class="profile-email">
<h4 class="text-primary">ADDRESS : <span class="text-muted"> {{$clients -> address}} </span></h4>
<h4 class="text-primary">REQUESTED DATE : <span class="text-muted"> {{\Carbon\Carbon::parse($pendingcases-> first() ->daterequested)->format('m/d/Y h:i A')}} </span> </h4>
<h4 class="text-primary">PHONE : <span class="text-muted">{{ $clients -> phone}} </span></h4>
<h4 class="text-primary">ADVOCATE : <span class="text-muted">{{ $clients -> Advocate_FirstName}} {{$clients -> Advocate_LastName}} </span></h4>
<div class="form-group row">
<div class="col-lg-8" id="reasonDropdown" style="display: none;">
<div class="d-flex align-items-center">
<h4 class="text-primary mr-2">REASON:</h4>
<select class="form-control" id="val-skill" name="val-skill">
<option value="">Please select</option>
<option value="html">Previously Helped</option>
<option value="css">Not Eligible</option>
</select>
</div>
</div>
</div>
function submitForm() {
$(document).ready(function() {
$('#submitButton').click(function(e) {
e.preventDefault();
// Get the form values
const decision = $('#decisionDropdown').val();
const reason = $('#val-skill option:selected').text(); // Retrieve the selected option's reason text
const caseId = $(this).data('case-id');
// Perform actions with the decision and reason values
//alert('Decision: ' + decision + '\nReason: ' + reason);
// Prepare the data to be sent
const formData = {
decision: decision,
reason: reason,
caseID: caseId
};
// Perform the AJAX request
$.ajax({
url: '/fulfillment',
type: 'POST',
data: formData,
dataType: 'json',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
success: function(response) {
console.log('Form submission successful:', response);
// Perform any additional actions after successful submission
},
error: function(error) {
console.error('Form submission failed dettaway:', error);
// Handle the error or display an error message
}
});
});
});
}
Route::post('/fulfillment', [CaseController::class, 'fulfillment'])->name('fulfillment.store');
public function fulfillment(Request $request) {
// if the case will be approved then the the first step is to delete the case from pending case and transfer it to fullfill case table
echo"hello world app ";
// get the case id or which is the same as the pending case id
$caseID = $request ->input('caseID');
dd($caseID);
}
Level 4
@NoLAstNamE I did already . This was causing the error
$fulfillmentCase -> save(); and then I fixed it to this
$fulfillmentCase->save();
Please or to participate in this conversation.