0

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>
KoenG
  • 25
  • 1
  • 6
  • Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) –  Oct 10 '19 at 10:00
  • No, there are 2 problems. Altough that thread did help in solving that second problem. (sort of) – KoenG Oct 10 '19 at 13:49
  • Here's example code: https://jsfiddle.net/khrismuc/4gvraL9d/ –  Oct 10 '19 at 14:33
  • True; but judging from your console output the server is the issue; it apparently sends nothing back. Allowing cross-domain requests has to happen on the server, and sending a proper reply also has to happen on the server, yet you've only posted client-side code. My comment answers your title question but your actual problem seems to be a different one. –  Oct 11 '19 at 07:49
  • Anyway, the request is a GET one, which makes testing easy. What happens if you put the final URL in the browser's address bar? Do you see the reply you're expecting? –  Oct 11 '19 at 07:50
  • Editing to add more info. – KoenG Oct 11 '19 at 08:24

0 Answers0