I have the next javascript above. I need it to send the data to a model where is Insert the information on a database. It is doing staff fine and the information is recorded but instead of sending me to the success function it sends me to the error function.
I am geting in the alert(jqxhr): {"readyState":0,"status":0,"statusText":"error"}
and in the console.log(jqxhr): {readyState: 0, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …}
thrownError seems empty in the alert and the console.log
I can't tell what's wrong in the code.
function newBenefit(){
var new_professional_id = document.getElementById("new_professional_id").value;
var new_service_code = document.getElementById("new_service_code").value;
var new_service_type = document.getElementById("new_service_type").value;
var new_service_condition = document.getElementById("new_service_condition").value;
var new_price_total = document.getElementById("new_price_total").value;
var new_price_patient = document.getElementById("new_price_patient").value;
var new_date_start = document.getElementById("new_date_start").value;
var new_date_end = document.getElementById("new_date_end").value;
$.ajax({
type: "POST",
url: "index.php?route=professionals/professional_edit_benefit_ajax",
data: {
action: 'new',
professional_id: new_professional_id,
service_code: new_service_code,
service_type_id: new_service_type,
service_condition_id: new_service_condition,
price_total: new_price_total,
price_patient: new_price_patient,
date_start: new_date_start,
date_end: new_date_end,
},
dataType: "json",
fail: function( jqXHR, textStatus, errorThrown ) {
alert(jqXHR);
},
error: function (jqxhr, ajaxOptions, thrownError) {
console.log(jqxhr);
console.log(thrownError);
alert(JSON.stringify(jqxhr));
alert(jqxhr.status);
alert(thrownError);
},
success: function(data){
console.log(data);
if(data=="1"){
//location.reload();
}else{
var continue_text='<?php echo $error_new_benefit_error; ?>';
swal({
type: 'error',
title: 'Oooops...',
text: continue_text,
});
}
}
});
}