How to capture RESPONSE from Ajax POST or PUT

I'm very new to Knack and even more recently introduced to java.

 

I've managed to muddle my way through the creation of an ajax POST that takes my data and posts it to an object successfully.  I see from the Knack documentation that after a POST there would be a response from Knack.  What I can't figure out is how to capture what the response is.

I would like to capture the response so that I can go on to use the newly created record's ID in subsequent ajax POSTS to other connected objects.

 

Here is the very simple ajax call that is working to post my data.

 

$.ajax({
              url: 'https://api.knackhq.com/v1/objects/object_38/records/',
              type: 'POST',
              headers: {
                                'X-Knack-Application-ID': '123XYZ',
                                'X-Knack-REST-API-Key': 'ZYX321'
                             },
              data: data

          });

 

I'm assuming I'm going to further this by adding in a "success" and "error" parameter to the ajax call and somehow gathering the response in the success parameter, but I have no idea where to begin doing that.

 

Can anyone help?

 

-Jeff

I figured it out... for the rest of you, here is the very simple way to get the record ID for the record you just posted.

 

// use an ajax call to insert the new record into the object 
$.ajax({
             url: 'https://api.knackhq.com/v1/objects/object_38/records/',
             type: 'POST',
             headers: {
                              'X-Knack-Application-ID': 'APP ID',
                              'X-Knack-REST-API-Key': 'API KEY'
                            },
             // post any data in the data variable

             data: data,
             // use data in success function to gather response from Knack
             success: function(data)
                           {
                             // pop up a message box showing successful data insert and hide the Knack wait spinner
                             alert ("Success: " + JSON.stringify(data));
                             // convert response data into useable variables
                             var postrecid = data.id;
                             alert ("Record ID: "+ postrecid);
                             Knack.hideSpinner();
                            },
              error: function(data)
                            {
                            // pop up a message box if the post failed and hide the Knack wait spinner
                            alert("Error: " + JSON.stringify(data));
                            Knack.hideSpinner();
                            }

//close ajax call

       });