title: return value from ajax success function
body: <p>i am trying to return value from ajax success function. but it is returning nothing.</p>
  
  <p>JS </p>
  
  <pre><code>function calculate_total_percentage(course_log_id){
      var total_percentage = 0;
      $.ajax({
          url:"teacher_internal_exam_management/get_exams_of_course_log/"+course_log_id,
          type: "POST",
          dataType: "json",
          success: function (exams_of_course_log) {
              for (var x = 0; x &lt; exams_of_course_log.length; x++) {
                  total_percentage += parseInt(exams_of_course_log[x].marks_percentage);
              }
              alert(total_percentage);
              return total_percentage;
          }
      });
  }
  </code></pre>
  
  <p>if i call like that</p>
  
  <pre><code>alert(calculate_total_percentage(course_log_id));
  </code></pre>
  
  <p>then showing '61' (due to call alert(total_percentage);) but 
  then showing 'undefined' why? It should show '61' twice? What is the problem?</p>