diff options
| author | schneefux <schneefux+commit@schneefux.xyz> | 2014-03-15 16:44:01 +0100 |
|---|---|---|
| committer | schneefux <schneefux+commit@schneefux.xyz> | 2016-08-15 19:46:42 +0200 |
| commit | c1cff6b4f451552ede0a351e43699c53dfe157df (patch) | |
| tree | 2407067782ee142e968aad590f3b199b7b434ec5 /js/index.js | |
| parent | a8894127ff068f1a7ba56c5abf698b9f5a76260b (diff) | |
| download | wvs-vplan-c1cff6b4f451552ede0a351e43699c53dfe157df.tar.gz wvs-vplan-c1cff6b4f451552ede0a351e43699c53dfe157df.zip | |
benutze jQuery für Ajax-Requests
Diffstat (limited to 'js/index.js')
| -rw-r--r-- | js/index.js | 55 |
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 = { |
