So I am developing a webapp that needs to communicate with another system on another domain. This communication needs to be async. And returns an XML document upon completion.
The problem however is that I cannot do cross-domain with XMLHttpRequest, and I cannot extract the data with fetch. Currently the furthest I have gotten is with fetch, where I am getting the data back, but I can't seem to extract it from the response.
The request code:
const HOST = "http://192.168.1.202:6363/"
function setobjval(name, value) {
fetch(HOST + 'setobjval?objid=' + name + '&objval=' + value, {
method: 'get',
mode: 'no-cors'
}).then(response => {
//I'm guessing the problem is here
console.log(response)
var xml = response.text()
console.log(xml)
//do stuff with the what is supposed to be xml
})
}
And the console:
interface.js:14 Promise {<pending>}
interface.js:9 Response {type: "opaque", url: "", redirected: false, status: 0, ok: false, …}
interface.js:10 Promise {<resolved>: ""}
So now I am writing this I see 2 problems:
1. The fact that I cant seem to extract the data from the response.
2. The fetch completes after the statements that are below it.
Okay so using the fiddle of @ChrisG https://jsfiddle.net/khrismuc/4gvraL9d/ I did get an error back in the console.
<html>
<body>
<parsererror style="display: block; white-space: pre; border: 2px solid #c77; padding: 0 1em 0 1em;
margin: 1em; background-color: #fdd; color: black">
<h3>This page contains the following errors:</h3>
<div style="font-family:monospace;font-size:12px">
error on line 1 at column 1: Extra content at the end of the document
</div>
<h3>Below is a rendering of the page up to the first error.</h3>
</parsererror>
</body>
</html>
And as far as what data i am expecting.
<response>
<result>OK</result>
<objid>long.object.id</objid>
<req>setobjval</req>
</response>