title: How to call a method of a javascript object inside ajax
body: <p>Given this code,</p>
  
  <pre><code>var submit = {
    send:function (form_id) {
      var url = $(form_id).attr("action");
      $.ajax({
        type: "POST",
        url: url,
        data: $(form_id).serialize(),
        dataType: 'json',
        success: function(result) {
          this.ret(result.message);
        },
        error: function(result) {
          // Some error message
        }
      });
    },
  
    ret:function (result) {
      this.result_data = result;
    },
  
    result_data:""
  };
  </code></pre>
  
  <p>will send a data from the form to a controller which if will return a json</p>
  
  <pre><code>$result['message'] = validation_errors();
  echo json_encode($result); 
  </code></pre>
  
  <p>I try to call this javascript object in this code,</p>
  
  <pre><code>var res = submit.send(form_id);
  </code></pre>
  
  <p>wherein <code>form_id</code> is the form <code>id</code>, and look for the output using </p>
  
  <pre><code>console.log(res);
  </code></pre>
  
  <p>In the console, it shows <code>undefined</code>. After searching for an explaination using google and stackoverflow itself I got the idea that,</p>
  
  <pre><code>this.ret(result.message);
  </code></pre>
  
  <p>is being called inside ajax which is another object, indicating that it's not part of it's method.</p>
  
  <p>My problem is, how to call the method <code>ret()</code> inside ajax?</p>
  
  <p>Is anyone can explain it to me?</p>