jquery - getJSON call succeeds but still throws 500 error -


i have getjson() call accesses view returns data. call works , data retrieved despite still getting 500 error.

failed load resource: server responded status of 500 (internal server error)  multivaluedictkeyerror @ /album_ajax/ "key u'reid' not found in <querydict: {}>"  request method: request url: http://127.0.0.1:8000/album_ajax/ django version: 1.4.3 python executable: /usr/bin/python python version: 2.7.1 python path: ['/users/santi/programming/feastfm', '/library/python/2.7/site-packages/pip-1.2.1-py2.7.egg', '/library/python/2.7/site-packages/south-0.7.6-py2.7.egg', '/system/library/frameworks/python.framework/versions/2.7/lib/python27.zip', '/system/library/frameworks/python.framework/versions/2.7/lib/python2.7', '/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/plat-darwin', '/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/plat-mac', '/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/system/library/frameworks/python.framework/versions/2.7/extras/lib/python', '/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/lib-tk', '/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/lib-old', '/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/lib-dynload', '/system/library/frameworks/python.framework/versions/2.7/extras/lib/python/pyobjc', '/library/python/2.7/site-packages'] 

i've looked on , tried asking around on irc haven't been able figure out why i'm getting error. syntax of view/call copied directly from: http://lethain.com/two-faced-django-part-5-jquery-ajax/

views.py

def get_album_tracks(request):     = request.get.copy()     reid = get["reid"]     url = "http://www.musicbrainz.org/ws/2/release/"+reid+"?fmt=json&inc=artist-credits+recordings"     data = urllib2.urlopen(url)     api_results = json.load(data)     tracks = []     entry in api_results['media']:         track in entry['tracks']:             artist = track['artist-credit'][0]['name']             title = track['title']             tracks.append({'artist':artist, 'title':title})     # results = {'reid':reid, 'tracks':tracks}     results = {'test':"is working?", "reid":reid, 'tracks':tracks}     return_json = simplejson.dumps(results)     return httpresponse(return_json, mimetype='application/json') 

the getjson() call

$.getjson("/album_ajax/", {"reid": reid}, function(json){         if(json['tracks']){             //alert("json?: " + json["tracks"]+" reid: "+json['reid']);             // var album = $('data-reid ='+)             for(var i=0; i<json['tracks'].length; i++){                 //console.log(json['tracks'][i]['title'])                 var artist = json['tracks'][i]['artist']                 var title = json['tracks'][i]['title']                 $(ul).append("<li class = 'album-track track' data-artist = '"+escape(artist) +"' data-title ='" + escape(title) +"'>"+artist +" - "+ title+"</li>");             }          }         else{             alert('no results')         }         }) 

i don't understand why getting both 500 error , having success function run.

edit

i put print statement inside view , looks view function being called twice, once empty querydict , once querydict containing reid variable:

album_tracks called <querydict: {}> album_tracks called <querydict: {u'reid': [u'0447570d-4804-49f1-9396-d71ddd8f59c4']}> 

i still not sure in code call made twice.

edit 2

including entire function has getjson() call

$('.album').click(function(e){     var $target = $(e.target);     // if(!$target.is("ul"))     if(!$target.is("div")) //magic happens here!!         {             return;         }     if($(this).children("li").length >= 1){         $(this).children("li").toggle();     }     else{         var reid = $(this).data('reid');         ul = this;         var data = {"reid": reid};         // var args = { type:"get", url:"/album/", data:data, complete:done };         // $.ajax(args);         $.getjson("/album_ajax/", data, function(json){         if(json['tracks']){             //alert("json?: " + json["tracks"]+" reid: "+json['reid']);             // var album = $('data-reid ='+)             for(var i=0; i<json['tracks'].length; i++){                 //console.log(json['tracks'][i]['title'])                 var artist = json['tracks'][i]['artist']                 var title = json['tracks'][i]['title']                 $(ul).append("<li class = 'album-track track' data-artist = '"+escape(artist) +"' data-title ='" + escape(title) +"'>"+artist +" - "+ title+"</li>");             }          }           else{             alert('no results')         }         })     } }); 

it turned out had multiple elements class, 1 of had data-attribute needed make ajax call work, other did not. both firing, 1 failing , other succeeding.

thanks @jesse-vogt telling me .album class in html code.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -