<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> <title>Данные формы</title> </head> <body> <form name="LoginForm" action="https://prostozaim.com.ua/login"> <input name="__RequestVerificationToken" type="hidden" value="KBJFK518pv_T9XaOTA8RbfVDxjXQkhfFIr3GFEmpt9d-ZNunk4rtDGYZ4GGWIILQiyKRlyZs548GLLe5H8c4rtNo9F9QUG1yTwZs-5UfZxg1"> <p><input name="loginEmail" id="LoginEmail"> <input type="password" name="LoginPassword" id="LoginPassword"></p> </form> <p><input type="submit" id="qw"></p> <div id="result"><div> <script> qw.onclick=function(){ var formdate = new FormData(document.forms.LoginForm); var xhr=new XMLHttpRequest(); xhr.withCredentials = true; xhr.open("POST", "https://prostozaim.com.ua/login", true); xhr.send(formdate); alert(xhr.responseText);}; </script> </body> </html> 

It is necessary with the help of the Ajax post request to authenticate at the specified URL from its form.

Tell me what is wrong? What is superfluous? Or how to do it?

    1 answer 1

    alert(xhr.responseText); will not work, since you are not waiting for an answer, immediately try to withdraw it. You need to write a server response event handler. And then make an alert

     var formdate = new FormData(document.forms.LoginForm); var xhr=new XMLHttpRequest(); xhr.withCredentials = true; xhr.open("POST", "https://prostozaim.com.ua/login", true); xhr.send(formdate); xhr.onreadystatechange = function() { if (xhr.readyState != 4) return; if (xhr.status != 200) { alert(xhr.status + ': ' + xhr.statusText); } else { alert(xhr.responseText); } }; 
    • Thank! Everything's great - combo
    • @sveimk Please mark the answer as correct. - Klym