I am not getting the expected result when trying to post a form using ajax.
I have a simple form. I also have a jquery script to submit the form so I can try to pre-validate a captcha text box before submitting the form.
I know this is something simple, but it’s driving me nuts.
What is supposed to do is post to a php page to validate the captcha. If what is entered does not match the captch, then the php page just echo “Validation Text is Invalid” then the jquery is supposed to do a simple alert message.
Unfortunately, the return I am getting appears to be the html from the current page not the text being returned.
I do not know if it makes a difference, but I am trying to post to a different page for validation other than what the post in the form says.
If it was working correctly (the way I am trying to get it to work), i would get an alert that says “Validation Text is Invalid”. My best guess is that I have some kind of syntax error that I am not seeing, or I am going about everything wrong.
Here is my jquery script:
$("#LogInForm").on("submit", function(e){
e.preventDefault();
var unameval = $.trim($("#UName").val());
var pwordval = $.trim($("#PWord").val());
var valtxtval = $.trim($("#ValidationTxt").val());
if (unameval.length == 0 || pwordval.length == 0 || valtxtval.length == 0)
{
$("#LogInErrMsgBar").show();
$("#LogInErrMsgTxt").html("<ul><li>Please complete all form fields</li><ul>");
}
else
{
var PostData = {uname: unameval,pword: pwordval,valtxt: valtxtval};
$.post("loginvalidations.php", {PostData}, function(result){
alert(result);
//$("#LogInErrMsgBar").show();
//$("#LogInErrMsgTxt").html(result);
});
}
});
The whole thing can be seen at https://wvsr.club/login