First AJAX makes a post to upload file now I just want this same AJAX when submitted to grab the data from second AJAX and post it together basically I want to post the Id back to the database, everything works just do not know how to combine the data together.

Code

 <script type="text/javascript">
        $(document).ready(function () {
            $('#submit').click(function () {
                var data = new FormData();
                var files = $('#fileupload').get(0).files;
                if (files.length > 0) {
                    data.append("UploadedFile", files[0]);
                }
                $.ajax({
                    type: "POST",
                    url: "ControllerHandler.ashx",
                    contentType: false,
                    processData: false,
                    data: data
                });

            });

            $.ajax({
                url: 'SelectType.ashx',
                method: 'Post',
                dataType: 'json', //make sure your service is actually returning json here
                contentType: 'application/json',
                data: '{}',
                success: function (data, status) {

                    $.each(data, function (i, d) {
                        $('#seasontype_select2').append('<option value="' + d.value + '">' + d.label + '</option>');
                    });

                }
            });
        });
    </script>
1

There are 1 answers

0
Louys Patrice Bessette On

Ajax requests can be nested.

$.ajax({
  // your Ajax params for this request
  // ...
  success: function(data){  // There only one argument provided here.
    // First callback
    var dataToSendAgain = data.something;

    $.ajax({
      // your Ajax params for this request
      // ...
      data: dataToSendAgain,
      success: function(data){  // There only one argument provided here.
        // Second callback
      }
    });
  }
});