Skip to content

Instantly share code, notes, and snippets.

@MinaGabriel
Created April 14, 2018 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MinaGabriel/f5d622b59422b1b0aa2d7d2e17fa335c to your computer and use it in GitHub Desktop.
Save MinaGabriel/f5d622b59422b1b0aa2d7d2e17fa335c to your computer and use it in GitHub Desktop.
Connect to server using JQuery
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(function(){
$("button").click(function(){
//get the value of both (username and password fields)
var username = $("#username").val();
var password = $("#password").val();
$.get( "http://45.55.135.13/?username=" + username + "&password=" + password, function( data ) {
data = $.parseJSON(data);
console.log(data);
if(data == "0 results"){
//display error message
alert("Wrong username and password");
}else {
//if correct display user first name from the Json object
alert(data.user_name);
}
});
});
});
</script>
</head>
<body>
username: <input type="text" id="username"/>
password: <input type="text" id="password"/>
<button>Login</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment