Thank you for your help! I can get the 'ok' in the alert with your code. However, how do I show the response in the alert? For some reason I am unable to pass the message back from the view; I keep getting an empty alert(response).
My view looks like:
def new_session(request):
if not request.is_ajax() or not request.method=='POST':
return HttpResponseNotAllowed(['POST'])
else:
request.session['key'] = json.loads(request.POST.get('details', '[]'))
return HttpResponse(request.session['key'])
I've also tried "return HttpResponse('ok')", but the 'ok' still didn't get passed to the load function. What do I do wrong? Any hints would be much appreciated!
voss
On Saturday, June 2, 2012 8:46:38 AM UTC-5, henzk wrote:
Hi,--
i haven't tested the code and never used dojo before, but sth. like
this should work:
var source1 = new dojo.dnd.Source("itemListNode");
var source2 = new dojo.dnd.Target("selectedListNode");
dojo.connect( source1, "onDndDrop",
function(source, nodes, copy, target){
//gather items and details
var details = [];
for( i=0; i < nodes.length; i++){
var item = this.getItem(nodes[i].id);
details.push(item.data);
}
//send details to server via AJAX POST request
dojo.xhrPost({
url: "/save_details/",
content: {details: JSON.stringify(details)},
// The success handler
load: function(response) {
alert('ok');
},
// The error handler
error: function() {
alert("error");
}
});
});
Explanation:
- changed 'item' to 'var item' ... without the 'var' item will be
global, which is probably not what you want.
- to get around making multiple requests to the server(one for each
dropped node), put the detail of each node in the details array.
- then json-encode and send this array to your django view (assumed to
be at '/save_details/')
- in the view, access the list as
json.loads(request.POST.get('details', '[]')) and place it into
request.session
As mentioned, the code is completely untested.
Good luck!
Yours,
Hendrik Speidel
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/lm_o18pvCe8J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.
No comments:
Post a Comment