Question

2
Replies
295
Views
Chinna Member since 2018 9 posts
Mindtree Ltd
Posted: 2 years ago
Last activity: 2 years 4 months ago
Closed

Unable to post data to server using XMLHttpRequest

Hi Team,

Actually I am trying to hit the server to post data(XML) from PEGA using XMLHttpRequest but I am getting the Http Status as "0" .Below event listener(onreadystatechange ) is not executing and send is failing with the message: callUrl.launchScreen(): Unexpected error: Failed to execute 'send' on 'XMLHttpRequest': Failed to load "URL".

Code:

function invokeInsertClaim(insertClaimXml)
{
try {
alert("callUrl.launchScreen(): screenInputXML=" + insertClaimXml);
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("POST","url",false);
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState === 4) {
if (xmlhttp.status === 200) {
alert("Done with status: " + xmlhttp.status + " and statusText: " + xmlhttp.statusText);
alert('xmlhttp.responseText: ' + xmlhttp.responseText);
return null;
} else {
var statusText = getErrorMsg(xmlhttp.status, xmlhttp.statusText);
alert(statusText);
return null;
}
}
};
xmlhttp.send(insertClaimXml);
} catch (e) {
alert("callUrl.launchScreen(): Unexpected error: " + e.message);
}

In above code if I make it as true(synchronous) it is executing the event listener(onreadystatechange ) but for false(asynchronous) it is not executing the event listener(onreadystatechange ) and getting exception:

callUrl.launchScreen(): Unexpected error: Failed to execute 'send' on 'XMLHttpRequest': Failed to load "URL".

Low-Code App Development Data Integration Java and Activities Data Integration
Moderation Team has archived post
Share this page LinkedIn