0

I have a python function and call this function by ajax . This function return a value as :

result= {'status' :1 ,'message' : ....}

How can i use this result in my js calculation function ? I try something like this :

<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 ;
    }  

0 Answers0