irigsoft Posted June 5, 2021 Share Posted June 5, 2021 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? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted June 6, 2021 Author Share Posted June 6, 2021 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'; Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 6, 2021 Share Posted June 6, 2021 2 hours ago, irigsoft said: uniURLFrame1.URL Hello, Why do you want to use uniURLFrame? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted June 6, 2021 Author Share Posted June 6, 2021 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 ? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 6, 2021 Share Posted June 6, 2021 7 minutes ago, irigsoft said: How to make this by client side using POST GET requests ? For example you can also analyze and use: AJAX - The XMLHttpRequest Object https://www.w3schools.com/js/js_ajax_http.asp Quote Link to comment Share on other sites More sharing options...
irigsoft Posted June 6, 2021 Author Share Posted June 6, 2021 2 minutes ago, Sherzod said: For example you can also analyze and use: AJAX - The XMLHttpRequest Object https://www.w3schools.com/js/js_ajax_http.asp Thanx, i will But i dont understand You, using this to get answer in uniURLFrame or instead ! What can I do if answer is JSON ? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 6, 2021 Share Posted June 6, 2021 2 minutes ago, irigsoft said: But i dont understand You, using this to get answer in uniURLFrame or instead ! Instead of UniURLFrame. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted June 6, 2021 Author Share Posted June 6, 2021 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> Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 6, 2021 Share Posted June 6, 2021 4 minutes ago, irigsoft said: What can I do if answer is JSON ? You will parse: https://www.w3schools.com/js/js_json_http.asp Quote Link to comment Share on other sites More sharing options...
irigsoft Posted June 6, 2021 Author Share Posted June 6, 2021 2 minutes ago, Sherzod said: You will parse: https://www.w3schools.com/js/js_json_http.asp Thanks, i will write if succeed. 1 Quote Link to comment Share on other sites More sharing options...
irigsoft Posted June 6, 2021 Author Share Posted June 6, 2021 @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 ? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 6, 2021 Share Posted June 6, 2021 3 minutes ago, irigsoft said: I make this on ButtonClick: You wanted to use it on the client side, didn't you? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted June 6, 2021 Author Share Posted June 6, 2021 3 minutes ago, Sherzod said: You wanted to use it on the client side, didn't you? Yes. I changed the sample code a bit. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 6, 2021 Share Posted June 6, 2021 1 minute ago, irigsoft said: Yes. I change little example code. In this case, you can additionally use ajaxRequest to send data to the server. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted June 6, 2021 Author Share Posted June 6, 2021 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. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 6, 2021 Share Posted June 6, 2021 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? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted June 6, 2021 Author Share Posted June 6, 2021 1 minute ago, Sherzod said: Are you passing the request parameters correctly? Yes, Quotes are used in third-party application parameters. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted June 6, 2021 Author Share Posted June 6, 2021 I can try request without quotes, but if use ' alert (this.responseText);' to show answer I get message: undefined Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 6, 2021 Share Posted June 6, 2021 I also see that double quotes in parameters are not escaped. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted June 6, 2021 Author Share Posted June 6, 2021 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 Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 6, 2021 Share Posted June 6, 2021 1 minute ago, irigsoft said: alert (this.responseText) Use in xhttp.onreadystatechange = function() {... Quote Link to comment Share on other sites More sharing options...
irigsoft Posted June 6, 2021 Author Share Posted June 6, 2021 Yes thanks, I will try to use urlencoding to ignore quotes. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted June 6, 2021 Author Share Posted June 6, 2021 @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();' ); Quote Link to comment Share on other sites More sharing options...
Sherzod Posted June 6, 2021 Share Posted June 6, 2021 You can try adding: xhttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); xhttp.setRequestHeader('Access-Control-Allow-Origin', '*'); Quote Link to comment Share on other sites More sharing options...
irigsoft Posted June 6, 2021 Author Share Posted June 6, 2021 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();' ); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.