summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--js/index.js55
1 files changed, 22 insertions, 33 deletions
diff --git a/js/index.js b/js/index.js
index 66b6d4e..53e905b 100644
--- a/js/index.js
+++ b/js/index.js
@@ -17,22 +17,18 @@
*/
function get_overview(){
- var req = new XMLHttpRequest();
+ var request = $.ajax({
+ type: "GET",
+ url: "http://***REMOVED***/moodle/course/view.php?id=2"
+ });
- req.onreadystatechange = function(){
- if(req.readyState == 4){
- if(req.status == 200 || window.location.href.indexOf("http") != -1){
- console.log('Übersichts-Request erfolgreich');
- return 1;
- }else{
- console.log('Etwas ist schiefgelaufen :(');
- return;
- }
- }
- }
+ request.done(function(msg){
+ console.log('Übersichts-Request erfolgreich');
+ });
- req.open("GET", "http://***REMOVED***/moodle/course/view.php?id=2", true);
- req.send();
+ request.fail(function(jqXHR, msg){
+ alert("Etwas ist schiefgelaufen: " + textStatus);
+ });
}
function login(){
@@ -42,30 +38,23 @@ function login(){
theme: "b",
});
- var req = new XMLHttpRequest();
-
var username = encodeURIComponent($("#username").value);
var password = encodeURIComponent($("#password").value);
var params = "username=" + username + "&password=" + password;
- req.onreadystatechange = function(){
- if(req.readyState == 4){
- if(req.status == 0){
- console.log("Es fehlt die Berechtigung, um auf den Server zuzugreifen.");
- return;
- }else if(req.status != 200 && window.location.href.indexOf("http") != -1){
- console.log("Etwas ist schiefgelaufen :(");
- return;
- }else{
- console.log('Login-Request erfolgreich');
- get_overview();
- }
- }
- }
+ var request = $.ajax({
+ type: "POST",
+ url: "https://***REMOVED***/moodle/login/index.php",
+ data: {username: username, password: password}
+ });
+ request.done(function(msg){
+ console.log('Login-Request erfolgreich');
+ get_overview();
+ });
- req.open("POST", "https://***REMOVED***/moodle/login/index.php", true);
- req.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
- req.send(params);
+ request.fail(function(jqXHR, textStatus){
+ alert("Etwas ist schiefgelaufen: " + textStatus);
+ });
}
var app = {