title: How to display returned JSON from a jQuery .ajax post
body: <p>Starting to work on a project that is built completely on JSON data. It is returned like this:</p>
  <pre><code>{&quot;location&quot;:{&quot;id&quot;:10,&quot;contactPhone&quot;:&quot;8675309&quot;,&quot;contactName&quot;:&quot;bob&quot;,&quot;name&quot;:&quot;bill smith&quot;,&quot;zipCode&quot;:&quot;90210&quot;,&quot;state&quot;:&quot;California&quot;,&quot;address1&quot;:&quot;104 S. Olive&quot;,&quot;city&quot;:&quot;Temecula&quot;,&quot;country&quot;:&quot;USA&quot;},&quot;success&quot;:true}
  </code></pre>
  <p>I am comfortable processing data returned in HTML form (usually tables) by traversing the DOM with the .find and other filtering to find success flags. I have no idea how to do this with JSON - I need to filter to the last object &quot;success&quot; and check if it is true or false. With HTML returned data I do it like this:</p>
  <pre><code>submitHandler: function(form) {
      $.ajax({
       //other ajax stuff
        success: function(data) {
          var answer = $(data).find(&quot;td:eq(1)&quot;).text();
          var message = $(data).find(&quot;td:eq(3)&quot;).text();
          //console.log(data);
          if (answer == &quot;True&quot;) {
            $('#messages').show().html(message);
        } else {
            $('#messages').show().html('Error logging in: ' + message);
        }
      }
    });
    return false;
    }
  </code></pre>
  <ol>
  <li>Even after using this method I don't completely understand what the
  function(<strong>data</strong>) means, Ive used <strong>data, msg and response</strong>
  without really understanding what the difference between them are.</li>
  </ol>
  <p>I am able to post to the webservice and get the returned JSON with this .ajax call</p>
  <pre><code>$.fn.serializeObject = function() {....}
  submitHandler: function(form){
      var wrapper = {};
      var location = {};
      wrapper.location = $(&quot;#newLocation&quot;).serializeObject();
          $.ajax({
              type: $(form).attr('method'),
              url: '/web/service/' + 'locationService' + '/' + 'createLocation',
              dataType: 'json',
              async: false,
              data: JSON.stringify(wrapper),
              success: function(msg) {
                      console.log('success' + msg );
                      //need to traverse to success and if true, do something
              },
                      error: function(msg) {
                      console.log('failure' + msg );
                      //need to traverse to success and if false, do something
              }
      });
      return false;
  }
  </code></pre>
  <ol>
  <li><p>How do you filter to the &quot;success&quot; part in a JSON string (string or object?)</p>
  </li>
  <li><p>What are the correct terms for the key/number pairs (is that even correct) in the JSON string IE &quot;<strong>contactPhone</strong>&quot;:&quot;<strong>8675309</strong>&quot;</p>
  </li>
  <li><p>How do you then display the data if &quot;success&quot;:&quot;true&quot; - I will work on that myself but if anyone has good method I would appreciate some advice. I would imagine you just appendTo a table somehow?</p>
  <p>I have a lot of questions on JSON, and am trying to word the questions in a general manner so that the help I am given can help someone else, I apologize for the length of this post. I appreciate any help and if requested will shorten/edit this question.</p>
  </li>
  </ol>