Commit 98543f2c by Piotr Mitros

Example of AJAX

parent 7dd659ba
......@@ -72,6 +72,11 @@ class RecommenderXBlock(XBlock):
data = pkg_resources.resource_string(__name__, path)
return data.decode("utf8")
@XBlock.json_handler
def handle_upvote(slef, data, suffix=''):
print "Upvote clicked!"
return {"Success": True}
# TO-DO: change this view to display your data your own way.
def student_view(self, context=None):
"""
......
function RecommenderXBlock(runtime, element) {
var handlerUrl = runtime.handlerUrl(element, 'handle_upvote');
function voted(result) { console.log("Voted"); }
$('.recommender_vote_arrow_up', element).click(function(){
$.ajax({
type: "POST",
url: handlerUrl,
data: JSON.stringify({}),
success: voted
});
});
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment