我有一个python函数,并通过ajax调用此函数。此函数返回值为:
result = {'status':1,'message':....}
如何在js计算函数中使用此结果? 我尝试这样的事情:
<script>
function get_result_by_code() {
var sum_insured = parseFloat($('#sum').val()) * 0.035
var promocode = parseFloat($('#bakcelPromo').val())
$.ajax({
method: "POST",
url: "{% url "appname:extract_json" %}" ,
async: false,
data: { "promocode": promocode },
success: function (response) {
if (response.status = 1) {
result= $.parseJSON(result);
result= data[0];
if (data == 1) {
sum_insured1 = sum_insured * 0.5
}
else {
sum_insured1 = sum_insured * 2.0 }
}
}
$('#output').html(response.message);
},
error: function () {
alert('There was an error communicating with the server.');
}
});
document.getElementById("premium").value = sum_insured1 ;
}