Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

Reload the content of a page several times with jQuery Ajax request to the node JS server

I'm programming a ServicePortal page for SAP as part of an internship, and I have a problem where I get stuck: It is a page with the ServiceCalls, i.e. tickets that have already been created, where the name of the contact person for the ticket is displayed in a separate column shall be. ServiceCalls The data in the columns on this page are filled via a request from the NodeJS WebServer to the SAP ServiceLayer API, i.e. data is returned to a function in the NodeJS Server using JASON from the API, then parsed into an array of objects, and then corresponding properties of objects are displayed the HTML page.

function listServiceCalls(inRes, inCustomerCode, inFrom){
log(`${serviceid}/ServiceCalls?$filter=CustomerCode eq '${inCustomerCode}'&skip=${inFrom}`);//Ausgabe in der Console

    request(
        {
            method: 'GET'
            , uri: `${serviceid}/ServiceCalls?$filter=CustomerCode eq '${inCustomerCode}'&$skip=${inFrom}&$top=20&$orderby=ServiceCallID desc`//Absteigend sortiert nach ServiceCallID alle ServiceCalls für Kundennummer mit der man eingeloggt ist ausgeben
            , headers: {
                Cookie: ` B1SESSION=${sessionid};`
            }
        }, (error, response, body) => {
            if (response.statusCode === 401) {
                console.warn('Fehler: error = ' + error + ' response = ' + response.statusCode + ' body = ' + body);//Von hier
                console.warn('error = "{}"; response = "{}"; body = "{}"', error, response.statusCode, body);//
                loginSAP();
            } else if (response.statusCode >= 300) {
                console.error('error = ' + error + ' response = ' + response.statusCode + ' body = ' + body);
                inRes.writeHead(response.statusCode, {'Content-Type': 'text/html'});
                inRes.end(body);}
             else {
                let calls = JSON.parse(body).value;
                let templatePage = fs.readFileSync("page/ListServiceCalls.html", "utf8");
                templatePage = templatePage.replace(/<<CustomerCode>>/g, inCustomerCode);
                let start = templatePage.indexOf('<!--ServiceCallStart-->') + '<!--ServiceCallStart-->'.length;
                let stop = templatePage.indexOf('<!--ServiceCallStop-->');
                let templateRow = templatePage.substring(start, stop);
                let page = "";
                let lines = "";
                if (calls) {
                    for (let i = 0; i < calls.length; i++) {
                        let obj = calls[i];
                        console.log(obj);
                        addStatusTextToCallObj(obj);
                        let template = '`' + templateRow + '
`';
                        let line = '';
                        let code = 'line = ' + template;
                        eval(code);
                        lines = lines + line;

                    }
                    page = templatePage.substring(0, start) + lines + templatePage.substring(stop);
                }
                inRes.writeHead(200, {'Content-Type': 'text/html'});
                inRes.end(page);
            }
        }
    );
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...