0

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 変数に格納する簡単な方法はありますか?

4

1 に答える 1

0

Dajax から JavaScript に値を格納する最も簡単な方法は次のとおりです。

dajax = Dajax()
value = 1
dajax.script('var i = %d;' % value)
return dajax.json()
于 2013-10-04T23:50:14.770 に答える