title: Read JSON returned by AJAX call
body: <p>I am new to AJAX. I am submitting my form data into a end point using AJAX. The endpoint is returning a json string with some response data. I tried many things but wasn;t able to read the JSON. </p>
  
  <p>I can parse the JSON. At this point, I want to figure out how I can read the JSON returned by the end point.</p>
  
  <p>My code so that posts to the end pint.</p>
  
  <pre><code>$('.ent-lead-form form').on('submit', function(e){
          e.preventDefault();
          var form = this;
  
          if($(this).find('.err').length == 0){
              $(this).parent().prepend('&lt;div class="form-mask"&gt;&lt;/div&gt;');
  
              $.ajax({
                  url: $(this).attr('action'),
                  type: 'POST',
                  data: $(this).serialize(),
                  success: function(data){
  
                      var data = JSON.parse(json);
                      alert(data);
  
                      // redirect to success or show thank you
                      if( $(form).find('input[name=successurl]').length == 1 ){
                          window.location = $(form).find('input[name=successurl]').val();
                      } else {
                          $(form).parent().prepend('&lt;div class="confirm-mask"&gt;Thank you for your submission.&lt;/div&gt;');
                      }
  
                      // cleanup
                      $('.form-mask').remove();
  
                  },
                  error: function(data){
                      // show error
                      $(form).parent().prepend('&lt;div class="confirm-mask"&gt;There was an error processing your request.  Please reload the page and try again.&lt;/div&gt;');
                      $('.form-mask').remove();
  
                  }
              });
  
  
         }
  });  
  </code></pre>