2017-04-20 244 views
-4

这是我code..where我要的那部分整合以及如何继续......如何获得在控制台响应(JSON格式),同时击中的URL

function  validate() { 
 

 
    var  un = document.loginscreen.uname.value; 
 

 
    var  pw = document.loginscreen.psw.value; 
 

 
    var  username =  "John_Smith"; 
 

 
    var  password =  "syntel123$"; 
 

 
    if  ((un == username) && (pw == password)) { 
 

 
    window.location =  "file:///C:/Users/KS5034674/Desktop/Gagile/WebContent/homescreen.html"; 
 

 
    return  true; 
 

 
    } else  { 
 

 
    console.log("login Failed"); 
 

 
    } 
 

 
}
form { 
 
    width: 100%; 
 
    border: 0px solid #f1f1f1; 
 
} 
 

 
.container { 
 
    padding: 16px; 
 
    text-align: center; 
 
} 
 

 
input[type=text], 
 
input[type=password] { 
 
    width: 100%; 
 
    height: 40%; 
 
    padding: 15px 10px 6px 9px; 
 
    margin-: 80px; 
 
    display: inline-tablecolumngroup; 
 
    border: 1px solid #ccc; 
 
    box-sizing: border-box; 
 
} 
 

 
#input_container { 
 
    position: absolute; 
 
    padding: 0 0 0 0px; 
 
    margin: 0 20px; 
 
    direction: ltr; 
 
    width: 80%; 
 
} 
 

 
#input { 
 
    height: 40px; 
 
    margin: 0; 
 
    width: 80%; 
 
    text-align: center; 
 
} 
 

 
#input_img { 
 
    position: absolute; 
 
    bottom: 10px; 
 
    left: 50px; 
 
    width: 20px; 
 
    height: 20px; 
 
} 
 

 
#input_container1 { 
 
    position: absolute; 
 
    padding: 0 0 0 0px; 
 
    margin: 0 20px; 
 
    direction: ltr; 
 
    width: 80%; 
 
} 
 

 
#input1 { 
 
    height: 40px; 
 
    margin: 0; 
 
    width: 80%; 
 
    text-align: center; 
 
} 
 

 
#input_img1 { 
 
    position: absolute; 
 
    bottom: 10px; 
 
    left: 50px; 
 
    width: 20px; 
 
    height: 20px; 
 
} 
 

 
button { 
 
    background-color: #0052A6; 
 
    color: white; 
 
    border: none; 
 
    cursor: pointer; 
 
    width: 70%; 
 
    height: 40px; 
 
} 
 

 
.imgcontainer { 
 
    text-align: center; 
 
    margin: 24px 0 12px 0; 
 
} 
 

 
img.syntel { 
 
    width: 40%; 
 
    border-radius: 0%; 
 
} 
 

 
img.agileimg { 
 
    width: 30%; 
 
    border-radius: 40%; 
 
} 
 

 
img.abc { 
 
    padding: 0 0px 0px 0px; 
 
    width: 20px; 
 
    height: 20px; 
 
} 
 

 
span.psw { 
 
    float: right; 
 
    padding-top: 16px; 
 
} 
 

 

 
/* Change styles for span and cancel button on extra small screens */ 
 

 
@media screen and (max-width: 300px) { 
 
    span.psw { 
 
    display: block; 
 
    float: none; 
 
    } 
 
    .cancelbtn { 
 
    width: 100%; 
 
    } 
 
}
<!DOCTYPE html> 
 

 
<html> 
 

 
<head> 
 

 
    <meta charset="utf-8"> 
 

 
    <meta name="viewport"  content="width=device-width, initial-scale=1"> 
 

 
     <link rel="stylesheet"  href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> 
 

 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
 

 
      <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> 
 

 

 

 
      <body> 
 

 
       <form name="loginscreen"  onsubmit="return validate()" action="file:///C:/Users/KS5034674/Desktop/Gagile/WebContent/homescreen.html"  method="post"  > 
 

 
       <div class="imgcontainer"> 
 

 
        <br> <br><br> 
 
        <img src=" C:\Users\KS5034674\Downloads\Gagile\project images\syntel.png"  alt="syntel"  class="syntel"> 
 

 
        <br><br><br> <br> 
 
        <img src=" C:\Users\KS5034674\Downloads\Gagile\project images\agileimg.png"  alt="agileimg"  class="agileimg"> 
 

 
         </div> 
 

 
         <br><br><br> 
 

 
         <div id="placeholder"  align="center"></div> 
 

 
         <div class="container"> 
 

 
          <div id="input_container"> 
 

 
          <input type="text"  id="input"  placeholder="Username"  name="uname"  required style="border-radius:7px;"> 
 

 
           <img src=" C:\Users\KS5034674\Downloads\Gagile\project images\username.png"  id="input_img"> 
 

 
           </div><br><br><br> 
 

 
           <div id="input_container1"> 
 

 
            <input type="password"  id="input1"  placeholder="Password"  name="psw"  required style="border-radius:7px;"> 
 

 
            <img src=" C:\Users\KS5034674\Downloads\Gagile\project images\password.png"  id="input_img1"> 
 

 
             </div> 
 

 
             </div> 
 

 
             <br><br>&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp 
 
             <img src=" C:\Users\KS5034674\Downloads\Gagile\project images\check.png"  class="abc">&nbsp&nbsp<small>Remember me</small> 
 

 
             <br><br><br> 
 
             <div class="container"> 
 

 
              <button type="submit"  >Login</button><br><br><br><br><br><br> 
 

 

 
</head> 
 

 
</form> 
 

 
</body> 
 

 
</html>

+0

请解释一下你的问题 –

+0

喜多并欢迎来到StackOverflow。有关如何提出问题,请参阅https://stackoverflow.com/help/how-to-ask这篇文章。请尽量简化您的代码,尽量减少您的需求,并且非常清楚您期望社区为您提供的帮助。 – Iceman

+0

@AmirMohsen实际上这是一个登录屏幕UI代码。现在我必须通过点击一个网址来使用api来响应 –

回答

0

你好,请使用此代码,这是获得数据的JSON后,你可以打网址 这是jsonv.json文件和验证()函数之后

{"user_name":"test","password":"testing"} 

function validate() { 
var jsdata; 
$.ajax({ 
     type: "GET", 
     url:"jsonv.json", 
     dataType: "json", 
     data: JSON.stringify({ 
      user_name: $("#input").val(), 
      password: $("#input1").val() 
     }), 
     success: function(response) { 
      jsdata=response; 
      var un = document.loginscreen.uname.value; 

      var pw = document.loginscreen.psw.value; 

      if ((un == jsdata.user_name) && (pw == jsdata.password)) { 
      alert(jsdata.user_name+'//'+jsdata.password); 
      //window.location = "file:///C:/Users/KS5034674/Desktop/Gagile/WebContent/homescreen.html"; 

      return true; 

      } else { 

       console.log("login Failed"); 

      } 
     }, 
     error: function(response) { 
      console.log(response); 
     } 
}); 
} 
+0

http://172.25.183.183:8080/JIRAservice/rest/login/...我必须在我的代码中添加此网址?我需要打这个网址,以回应 –

+0

它不会移动到下一页,如果它成功登录 –

0

,如果您有存储在任何网址上的数据,那么你可以张贴一个AJAX网址:'如果你想登录打开新页面相同的标签后成功再使用_self

function validate() { 
var jsdata; 
$.ajax({ 
     type: "POST", 
     url:"http://172.25.183.183:8080/JIRAservice/rest/login/", 
     dataType: "json", 
     data: JSON.stringify({ 
      user_name: $("#input").val(), 
      password: $("#input1").val() 
     }), 
     success: function(response) { 
      jsdata=response; 
      var un = document.loginscreen.uname.value; 

      var pw = document.loginscreen.psw.value; 

      if ((un == jsdata.user_name) && (pw == jsdata.password)) { 
       var myWindow = window.open("file:///C:/Users/KS5034674/Desktop/Gagile/WebContent/homescreen.html", "_self"); 
      return true; 

      } else { 

       console.log("login Failed"); 

      } 
     }, 
     error: function(response) { 
      console.log(response); 
     } 
}); 
} 
+0

是的..我已经尝试过......它不工作 –