在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/網(wǎng)絡安全  HTML  Office/ easymock怎么做判斷

easymock怎么做判斷

問題描述

沒有辦法動態(tài)改變返回數(shù)據(jù)中success的值

問題出現(xiàn)的環(huán)境背景及自己嘗試過哪些方法

我用ajax做一個登錄界面,因為沒有后臺所以使用了easymock來寫假數(shù)據(jù),但是發(fā)現(xiàn)ajax返回的數(shù)據(jù)中的success一直是固定值。不能像php中那樣動態(tài)變化

html代碼

<div id="wrapper">
    <h1 id="title">登陸界面</h1>
    <div id="content">
        <label for="username">用戶名</label>
        <input type="text" id="username" value>
        <br/>
        <label for="pass">密碼</label>
        <input type="password" id="pass" value>
    </div>
    <div id="btn">
        <button id="login">登錄</button>
        <a href="#">新用戶?在此注冊</a>
    </div>
</div>

js代碼:

var username=document.getElementById("username").value;
var pass=document.getElementById("pass").value;
var btn=document.getElementById("login");
var xhr;
btn.onclick=function () {

if(window.XMLHttpRequest){
    xhr=new XMLHttpRequest();
}
else{
    xhr=new ActiveXObject("Microsoft.XMLHttpRequest");
}
xhr.open("get","https://easy-mock.com/mock/5b57d2a603a5844b1c942098/user/query?name="+username+"&pass="+pass,true);
xhr.send();
xhr.onreadystatechange=function () {
    if(xhr.readyState==4){
        if(xhr.status==200){
            console.log("連接服務器成功");
            var data=JSON.parse(xhr.responseText);
            console.log(data);
            if(data.success){
                window.location.href="indexJS.html"
            }
            else{
                alert("賬戶名或密碼錯誤,請重新輸入");
            }
        }
    }
}

}

easymock數(shù)據(jù)

你期待的結果是什么?實際看到的錯誤信息又是什么?

我希望能夠先判斷一下填寫的數(shù)據(jù)是否存在于模擬數(shù)據(jù)中,如果存在則讓返回數(shù)據(jù)中的success為true

回答
編輯回答
舊酒館

問題已解決,
使用_req對象,通過_req.query屬性獲取到參數(shù)值,判斷是否等于其中的一個值,如果是的話就返回true。不是就返回false

2017年6月29日 14:29