0

I'm working on an ajax call to an API. and upon calling this call, I keep running into this error. Please help. Ive been trying at this for hours and not sure what the issue is. Ive taken out the

JSON.parse and added them back to see if that will help but still no progress.

 $.ajax({
        type: "POST",
         //url: 'http://aeM/api/getDataId',
        url: '/bin/soupservice.getDataAccordToId.html',
        //async: false,
        data: IDschema,
        //contentType: "application/json",
        beforeSend: function () {
            // Show image container
            $("#wait").css("display", "block");
        },
        
    success:function (data, textStatus, jqXHR) {
    console.log(jqXHR.status);
   
        if (JSON.parse(data)) {
            let fileDeviceData = [];
            let uploadDate = [];
            fileDeviceData = data;
            let deviceNameFromFileData = [];
            $.each(JSON.parse(data), function (i, element) {
                dataInFile.push(element.file);
                deviceNameFromFileData.push(element.deviceName);
                //push an object while interacting with API. used to get similar index locations for later use
                duplicateIdCheckedList.push({
                    "deviceName":element.deviceName,
                    "lastUploadDate":element.lastUploadDate.split(" ")[0] ,
                    "fileName": element.deviceName+ " "+element.lastUploadDate.split(" ")[0],
                    "id":element.id
                    
    
                });
                let utcTime = element.lastUploadDate;
                let utcText = moment(utcTime).format("L LT");
                let anotherway = moment.utc(utcTime).local().format("L LT");
                let firstConvertedString = anotherway.split("/").join("-").replace(",", "");
                uploadDate.push(firstConvertedString.split(":").join("-").replace(",", ""));
            })
            //call on the findDuplicateIndex function to organize all the files that will be consolidated together
            duplicates=findDuplicateIndex(duplicateIdCheckedList);
            valuesforBrowserTime = uploadDate
            exportAsTxt(deviceNameFromFileData, valuesforBrowserTime);
        }

1 Answer 1

1

I see you are requesting a .html file and passing data to JSON.parse that expect a JSON format.

You may need to parse using a different method.

Sign up to request clarification or add additional context in comments.

7 Comments

any idea what method to use??
If you are in the browser you could use innerHTML of some element. Then you can walk the DOM. In NodeJS you could use something like cheerio
@ user12750353 im using Jquery. any clue on how to do it in that framework?
do you see the $.each function I have?? How would using nodes work for getting attributes from each element??
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.