0

I am working with APIs. My logic is 1st add a grade (POST), 2nd get the gradeID (GET), 3rd add grades to students (PUT). My problem is that I have to use the gradeID in the API call to add the grades. How do I do using AJAX to get the result from one call and then pass to another call?

here is my ajax:

  $.ajax({
          type: 'post',
          url: "doRequest.php",
          data: postData,
          success: function(data) {
            var output = {};
            if(data == '') {
              output.response = 'Success!';
            } else {
              try {
                output = jQuery.parseJSON(data);
              } catch(e) {
                output = "Unexpected non-JSON response from the server: " + data;
              }
            }
            $('#statusField').val(output.statusCode);
            $('#responseField').val(format(output.response));
            $("#responseField").removeClass('hidden');
            $("#responseFieldLabel").removeClass('hidden');
          },
          error: function(jqXHR, textStatus, errorThrown) {
            $('#errorField1').removeClass('hidden');
            $("#errorField2").innerHTML = jqXHR.responseText;
          }
  });
}

Is there a way tho have an ajax inside of other?

Maple
  • 183
  • 8
  • you can create the second ajax in the success function of first and pass the data. – shubham Feb 13 '19 at 16:47
  • https://stackoverflow.com/questions/54641013/save-ajax-jquery-selector-in-an-array - see the promise approach in one of the answers on a question you've asked before with the same code. – mitkosoft Feb 15 '19 at 06:45

0 Answers0