Created
April 14, 2018 15:32
-
-
Save MinaGabriel/f5d622b59422b1b0aa2d7d2e17fa335c to your computer and use it in GitHub Desktop.
Connect to server using JQuery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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