Permalink
Browse files

Make GET requests send args to dajaxice. #39

  • Loading branch information...
1 parent 2cffacc commit f878f5e845bee2e511c70e7fd87992fa21f7569e @jorgebastida committed Sep 2, 2012
@@ -34,10 +34,14 @@ var Dajaxice = {
error_callback = custom_settings['error_callback'];
}
- var send_data = 'argv='+encodeURIComponent(JSON.stringify(argv));
- var oXMLHttpRequest = new XMLHttpRequest;
+ var send_data = 'argv='+encodeURIComponent(JSON.stringify(argv)),
+ oXMLHttpRequest = new XMLHttpRequest,
+ endpoint = '{% url 'dajaxice-endpoint' %}'+dajaxice_function+'/';
- oXMLHttpRequest.open(method, '{% url 'dajaxice-endpoint' %}'+dajaxice_function+'/');
+ if(method == 'GET'){
+ endpoint = endpoint + '?' + send_data;
+ }
+ oXMLHttpRequest.open(method, endpoint);
oXMLHttpRequest.setRequestHeader("X-Requested-With", "XMLHttpRequest");
oXMLHttpRequest.setRequestHeader("X-CSRFToken", Dajaxice.get_cookie('csrftoken'));
oXMLHttpRequest.onreadystatechange = function() {
@@ -57,7 +61,12 @@ var Dajaxice = {
}
}
}
- oXMLHttpRequest.send(send_data);
+ if(method == 'POST'){
+ oXMLHttpRequest.send(send_data);
+ }
+ else{
+ oXMLHttpRequest.send();
+ }
return oXMLHttpRequest;
},
View
@@ -19,3 +19,8 @@ def bye(request):
@dajaxice_register
def lol(request):
return simplejson.dumps({'message': 'lol'})
+
+
+@dajaxice_register(method='GET')
+def get_args(request, foo):
+ return simplejson.dumps({'message': 'hello get args %s' % foo})
@@ -8,5 +8,6 @@
<button onclick="Dajaxice.simple.bye(function(d){alert(d.message);})">Bye</button>
<button onclick="Dajaxice.more.complex.bye(function(d){alert(d.message);})">Complex Bye</button>
<button onclick="Dajaxice.simple.lol(function(d){alert(d.message);})">LOL</button>
+ <button onclick="Dajaxice.simple.get_args(function(d){alert(d.message);}, {'foo': 'var'})">GET args</button>
</body>
</html>

0 comments on commit f878f5e

Please sign in to comment.