Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to import XMLHttpRequest module in JavaScript processor

I need to send a HTTP post request using a JavaScript processor. My code looks like this:

var xhr = new XMLHttpRequest();
var url = "url";
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type",
"application/json");
xhr.onreadystatechange = function () {
    if (xhr.readyState === 4 && xhr.status === 200) {
        var json = JSON.parse(xhr.responseText);
        console.log("Successfully ingested the batch " + json);
    }
};
var data = JSON.stringify(payload);
xhr.send(payload);

On previewing, I get the below error:

"com.streamsets.pipeline.api.base.OnRecordErrorException: SCRIPTING_04 - Script sent record to error: ReferenceError: "XMLHttpRequest" is not defined"

As I understand, there is no such thing as importing modules in JavaScript, how do I use modules like XMLHttpRequest? Please guide. Thanks.