i'm trying to show error message from server to client site using ajax , but it wont work when i make a function for error messages ,
#other codes for saving the post,there is not error
success_meesage = f'success'
return JsonResponse({'success':'success','success_msg':success_meesage})
else:
error_message=f'there is an error into your two dates please make sure check in smaller than check out'
return JsonResponse({'success':False,'error_taken':True,'error_message':error_message})
my ajax code
const form = document.getElementById('post-form')
form.addEventListener("submit",submitHanler);
function submitHanler(e){
e.preventDefault();
$.ajax({
type:'POST',
url:"my-url",
data:$("#post-form").serialize(),
dataType:'json',
success:successFunction,
error:errorFunction,
})
}
function successFunction(data){
// console.log(data)
if(data.success='success' && data.success_msg){
form.reset();
alertify.success(data.success_msg)
}
}
function errorFunction(request, status, error){
console.log(request.responseText)
if(error.error_taken == true){
alertify.alert('warning !','message')
alertify.alert(error.error_message,function(){
});
}
}
}
function errorFunction(jqXHR, exception)
it shows nothing as well , i tried many ways but none of them worked !
thank you in advance ..
return JsonResponse({'success':False,'error_taken':True,'error_message':error_message}, status=400)