如何使用Ajax获取用户身份验证请求?

时间:2015-11-27 07:48:31

标签: ajax

如何使用带有MD-5哈希算法的用户身份验证的Ajax GET请求?

1 个答案:

答案 0 :(得分:0)



    <script type="text/javascript">
 
 
function sendRequest(username, password)
{
    var url = "http://ajaxref.com/ch7/protectedhash.php";
     var options = { method: "GET",
                  username : username,
                  password : AjaxTCR.data.encodeMD5(password),
                  onSuccess : showResponse,
                  onFail : showFail};
  
  AjaxTCR.comm.sendRequest(url,options);
}
 
function showFail(response, message)
{
    var responseOutput = document.getElementById("responseOutput");
    responseOutput.innerHTML = "<h3>Error:</h3>" + message;
}
 
function showResponse(response)
{
    var responseOutput = document.getElementById("responseOutput");
    responseOutput.innerHTML = response.xhr.responseText;
    //document.location =  "http://ajaxref.com/ch7/protectedhash/myprotectedpage.php";
}
 
window.onload = function () 
{ 
 document.requestForm.requestButton.onclick = function () { sendRequest(this.form.txtUser.value, this.form.txtPass.value); };
};
</scr
&#13;
&#13;
&#13;