Make Ajax Call

When the user has uploaded the pdf file, we need to make a POST call to a servlet and pass the uploaded PDF document in the POST request. The POST request returns a path to the exported data in the crx repository

$("#fileElem").on('change', function (e) {
           console.log("submitting files");
           var filesUploaded = e.target.files;
           var ajaxData = new FormData($("#myform").get(0));
           for (var i = 0; i < filesUploaded.length; i++) {
               ajaxData.append(filesUploaded[i].name, filesUploaded[i]);
           }

           handleFiles(ajaxData);

       });

function handleFiles(formData) {
    console.log("File uploaded");

    $.ajax({
        type: 'POST',
        data: formData,
        url: '/bin/ExtractDataFromPDF',
        contentType: false,
        processData: false,
        cache: false,
        success: function (filePath) {
            console.log(filePath);
            guideBridge.setData({
                dataRef: filePath,
                error: function (guideResultObject) {
                    console.log("Error");
                }
            })


        }
    });
}

The servlet mounted on /bin/ExtractDataFromPDF extracts the data from the PDF file and returns the path of the crx node where the extracted data is stored.
The GuideBridge setData method is then used to set the data of the adaptive form.

Next Steps

Deploy the sample assets

recommendation-more-help
8de24117-1378-413c-a581-01e660b7163e