dajaxを使用してajax関数から単純な値を返したいだけですが、それほど単純ではないようです:
## python
@dajaxice_register
def get_selected_option_value(request, id):
"""
return my value
"""
dajax = Dajax()
try:
item = Item.objects.get(pk=id)
value = item.price
value = "%.2f" % value
except Item.DoesNotExist:
value = 0
dajax.add_data(value, 'get_value')
return dajax.json()
// js
function getValFromOption(option){
Dajaxice.gpf2.get_selected_option_value(Dajax.process, {'id':$(option).attr('value')});
}
function get_value(data){
return data;
}
私はまだこのエラーが発生します:
Uncaught ReferenceError: get_value is not defined
Dajax 関数から値を返し、それを js 変数に格納する簡単な方法はありますか?