Explorar o código

Use js to submit consol updat

Colin Powell %!s(int64=3) %!d(string=hai) anos
pai
achega
3bd5cb06e8
Modificáronse 1 ficheiros con 23 adicións e 0 borrados
  1. 23 0
      templates/games/gamesystem_detail.html

+ 23 - 0
templates/games/gamesystem_detail.html

@@ -3,6 +3,29 @@
 
 {% block title %}{{object.name}}{% endblock %}
 
+{% block extra_head %}
+    <script>
+    $('#library-update-form').on('submit', function(event){
+        event.preventDefault();
+        console.log("form submitted!")  // sanity check
+        $.ajax({
+            url : "library/update/",
+            type : "GET",
+            // handle a successful response
+            success : function(json) {
+                $('#library-update-form').html("<button id='library-update-btn' class='btn btn-secondary my-2 my-sm-0' type='submit' disabled>Update</button>");
+                console.log(json); // log the returned json to the console
+            },
+
+            // handle a non-successful response
+            error : function(xhr,errmsg,err) {
+                console.log(xhr.status + ": " + xhr.responseText); // provide a bit more info about the error to the console
+            }
+        });
+    });
+    </script>
+{% endblock %}
+
 {% block content %}
     <h4>Browsing {{object_list.count}} games</h4>