Jump to content

How to get content of uniURLFrame


irigsoft

Recommended Posts

Hello.

I'm trying to get the content response to uniURLFramе1.URL: = 'http: // localhost: 4444'
The result is an XML string.

The situation is as follows:

1. I install an external application and it listens on port 4444

2. I send cURL and receive a response in XML

To publish a url I use uniURLFrame.URL: = 'http: // localhost: 4444 / settings (com = "mydeviceID", tcp = 0)'
and if the execution is successful, I get XML with data.

So, my problem is how to execute a URL in Frame and read a response from uniURLFrame?

Link to comment
Share on other sites

More information:

1. Start the connection to a server application (third party server) with uniURLFrame1.URL: = 'http://localhost:4444'
2. I wait until I get the answer - uniURLFrame1 loads xml. (How do I know when the server is responding?)

3. Send the next command with uniURLFrame1.URL: = 'http://localhost:4444/nextcommand';

Link to comment
Share on other sites

19 minutes ago, Sherzod said:

Hello,

Why do you want to use uniURLFrame?

Hello,

there is communication between webbrowser (my uniGui Application) and third party software  to communicate with device.

I send cURL to third party server application and wait answer.

When I use server side i have many methods to get answer and work on it, but I don't know how to make this on clientside.

1. I have mobile device that use my unigui application on mobile web browser

2. on this device is installed third  party server software

3. All communication is on client side.

How to make this by client side using POST GET requests ?

Link to comment
Share on other sites

1 minute ago, Sherzod said:

Instead of UniURLFrame.

I make my test https://www.w3schools.com/js/tryit.asp?filename=tryjs_ajax_xmlhttp:

but nothing hapend?

<!DOCTYPE html>
<html>
<body>

<h2>The XMLHttpRequest Object</h2>

<p id="demo">Let AJAX change this text.</p>

<button type="button" onclick="loadDoc()">Change Content</button>

<script>
function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("demo").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "https://google.com", true);
  xhttp.send();
}
</script>

</body>
</html>

Link to comment
Share on other sites

@Shertzog, please help .

I make this on ButtonClick:

var

sAnswer : String;

begin

UniSession.addJS (
        '  var xhttp = new XMLHttpRequest();'
      + '  xhttp.onreadystatechange = function() {'
      + '    if (this.readyState == 4 && this.status == 200) {'
      + '      document.getElementById("' + UniMemo1.JSName + '").innerHTML = this.responseText;'
      + '    }'
      + '  };'
      + '  xhttp.open("POST", "http://localhost:4444/settings(com="com1",tcp=0)", true);'
      + '  xhttp.send();'
);

end;

How to get answer in sAnswer ?

Link to comment
Share on other sites

8 minutes ago, Sherzod said:

In this case, you can additionally use ajaxRequest to send data to the server.

I am sorry,

It is possible some how to get answer with xmlrequest and uniMemo.Lines.Add (answer) on clientside.

1. Click Button

2. Fire uniSession.addJS (xttprequest function)

3. UniSession.addJS (
        '  var xhttp = new XMLHttpRequest();'
      + '  xhttp.onreadystatechange = function() {'
      + '    if (this.readyState == 4 && this.status == 200) {'
      + '      document.getElementById("' + UniMemo1.JSName + '").innerHTML = this.responseText;'
      + '    }'
      + '  };'
      + '  xhttp.open("POST", "http://localhost:4444/settings(com="com1",tcp=0)", true);'
      + '  xhttp.send();'

     + ' alert (this.responseText)'
);

I get some error when try to execute example code.

Link to comment
Share on other sites

2 minutes ago, irigsoft said:

      + '  xhttp.open("POST", "http://localhost:4444/settings(com="com1",tcp=0)", true);'

 

2 minutes ago, irigsoft said:

I get some error when try to execute example code.

Are you passing the request parameters correctly?

Link to comment
Share on other sites

1 minute ago, Sherzod said:

I also see that double quotes in parameters are not escaped.

Can You tell me why i get "undefined" when use ' alert (this.responseText);', that will help me to get answer

I use copy/past from https://www.w3schools.com/ and I thing 'this' is not correct for my unigui application, maybe document ot window will help to get responce, but it is not working too

Link to comment
Share on other sites

@Sherzod,

It is OK - I get in uniMemo1.Text answer of my GET request:

UniSession.addJS ('  var xhttp = new XMLHttpRequest();'
      + '  xhttp.onreadystatechange = function() {'
      + '    if (this.readyState == 4 && this.status == 200) {'
      + '      document.getElementById("' + UniMemo1.JSName + '_id").innerHTML = this.responseText;'
      + '    }'
      + '  };'
//      + '      alert("' + UniEdit_URL.Text + 'settings(com=' + UniEdit_FDID.Text + ',tcp=0)");'
      + '  xhttp.open("GET", ''' + UniEdit_URL.Text + 'settings(com="' + UniEdit_FDID.Text + '",tcp=0)'', true);'
      + '  xhttp.send();'
      );

Link to comment
Share on other sites

2 minutes ago, Sherzod said:

You can try adding:


xhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); 
xhttp.setRequestHeader('Access-Control-Allow-Origin', '*');

 

Big thanks,

I made it by this code, all what i want:

UniSession.addJS ('  var xhttp = new XMLHttpRequest();'
      + '  xhttp.onreadystatechange = function() {'
      + '    if (this.readyState == 4 && this.status == 200) {'
      + '      document.getElementById("' + UniMemo1.JSName + '_id").innerHTML = this.responseText;'
      + '    }'
      + '  };'
//      + '      alert("' + UniEdit_URL.Text + 'settings(com=' + UniEdit_FDID.Text + ',tcp=0)");'
      + '  xhttp.open("GET", ''' + UniEdit_URL.Text + 'settings(com="' + UniEdit_FDID.Text + '",tcp=0)'', true);'
      + '  xhttp.send();'
      );

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...