I want to submit a form using ajax. So I am not using the type=submit
. I am using a onClick
event on a link(<a>
) to send the form data using ajax. I also want to take advantage of HTML5 form validation capabilities.
So before sending the data, I used the function .checkValidity
to check the validity of the form.
If it returns true then I send the data. But when it return false I want to show user that the form is invalid using HTML5 default notifying scheme. But I don't know how to trigger that.
Is there is any way to show the validation of the form programmatically.
One way to do is trigger the submit event if checkValidity
return false. But this will refresh the page. I don't want to change the state of the page.
checkValidity
only checks validity and inform the program. It doesn't inform the user interactively.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…