I am using the following code to send my username and password to backend. The reason that I am sending them in this way is that I am showing the login form in a lightbox and need to show the result messages "You are authenticated", "Not authorized" in the lightbox without closing it.
<form id="authform" onsubmit="return authenticate()">
...
I am wondering if it is a secure practice to send the username and password through ajax to backend? if it is not what would be a better approach as I need to show the form in a lightbox and need to keep it open to show the results.