Frederick Posted July 22, 2022 Share Posted July 22, 2022 I set the URL property of a TUniURLFrame to a URL that returns a single value. The value can be seen in the TUniURLFrame. The following event is not fired. procedure TfrmShare.UniURLFrame1AjaxEvent(Sender: TComponent; EventName: string; Params: TUniStrings); begin showmessage(params.Text); end; How do I read the value returned by the URL? -- Frederick (UniGUI Complete - Professional Edition 1.90.0.1562) Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 22, 2022 Share Posted July 22, 2022 22 minutes ago, Frederick said: The following event is not fired. ? Are you calling? Quote Link to comment Share on other sites More sharing options...
Frederick Posted July 22, 2022 Author Share Posted July 22, 2022 2 minutes ago, Sherzod said: ? Are you calling? Yes. UniFrame1.URL:='<url>'; and check event OnAjaxEvent. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 22, 2022 Share Posted July 22, 2022 2 hours ago, Frederick said: UniFrame1.URL:='<url>'; It doesn't fire the AjaxEvent. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 23, 2022 Share Posted July 23, 2022 20 hours ago, Frederick said: UniFrame1.URL:='<url>'; Could you please make a simple testcase? Quote Link to comment Share on other sites More sharing options...
Frederick Posted July 23, 2022 Author Share Posted July 23, 2022 1 hour ago, Sherzod said: Could you please make a simple testcase? Here you go. -100 is displayed in the TUniURLFrame after I click the button. I would like to read this value. urlframe.7z Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 23, 2022 Share Posted July 23, 2022 21 minutes ago, Frederick said: urlframe.7z 53.79 kB · 0 downloads Are you on the same domain? Quote Link to comment Share on other sites More sharing options...
Frederick Posted July 23, 2022 Author Share Posted July 23, 2022 5 minutes ago, Sherzod said: Are you on the same domain? No. I am running the application in my own computer (localhost) while the URL is a public web site. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 23, 2022 Share Posted July 23, 2022 Do you have to use UrlFrame? Quote Link to comment Share on other sites More sharing options...
Frederick Posted July 23, 2022 Author Share Posted July 23, 2022 6 minutes ago, Sherzod said: Do you have to use UrlFrame? No. My objective is to call the URL, get a response value and save/use it. I am open to using any other method to achieve the result. Since I am using UniGUI, I thought of using its components first. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 23, 2022 Share Posted July 23, 2022 1 hour ago, Frederick said: No. My objective is to call the URL, get a response value and save/use it. I am open to using any other method to achieve the result. Yes, you need to use a server solution, for example using IdHTTP. Quote Link to comment Share on other sites More sharing options...
irigsoft Posted July 23, 2022 Share Posted July 23, 2022 hello, try with this UniSession.AddJS ( ' new Promise(function(resolve, reject) {' + ' const xhttp = new XMLHttpRequest();' + ' xhttp.open("GET", ''' + fURL + TRIM (cmd) + ''', false);' + ' xhttp.send(null);' + ' var sRes = xhttp.responseText;' + ' if (sRes != "") {' + ' ajaxRequest (' + myMemo.JSName + ' , "FiscalAnswer", ["_value=" + "" + sRes + "","_cmd=" + "' + sCMD + '"]);' + ' };' //if sRes <> '' + ' document.getElementById("' + myMemo.JSName + '_id").innerHTML = this.responseText;' + '});'//end Promise ); this open url with parameters and get result in ajaxrequest and memo Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 23, 2022 Share Posted July 23, 2022 1 hour ago, irigsoft said: const xhttp = new XMLHttpRequest();' + ' xhttp.open("GET", ''' + fURL + TRIM (cmd) + ''', false);' + ' xhttp.send(null);' This will also be blocked by CORS policy. Quote Link to comment Share on other sites More sharing options...
Frederick Posted July 23, 2022 Author Share Posted July 23, 2022 2 hours ago, Sherzod said: Yes, you need to use a server solution, for example using IdHTTP. Thanks for the tip. The following code works for me:- idHttp:=TIdHttp.Create(NIL); try showmessage(idHttp.Get(<url>)); finally idHttp.Free; end; Quote Link to comment Share on other sites More sharing options...
Frederick Posted July 23, 2022 Author Share Posted July 23, 2022 1 hour ago, irigsoft said: this open url with parameters and get result in ajaxrequest and memo Thanks for the code. However, I am getting no response from the URL. Maybe, the URL just returns a string value and your code does nothing for it or like Sherzod mentioned, the code is not being executed or allowed to execute because of a blocked CORS policy? Quote Link to comment Share on other sites More sharing options...
irigsoft Posted July 23, 2022 Share Posted July 23, 2022 13 minutes ago, Frederick said: the code is not being executed or allowed to execute because of a blocked CORS policy? yes, CORS policy is the problem. Quote Link to comment Share on other sites More sharing options...
Oliver Morsch Posted July 23, 2022 Share Posted July 23, 2022 If you have the target server under control, then you can configure CORS there... Quote Link to comment Share on other sites More sharing options...
Frederick Posted July 23, 2022 Author Share Posted July 23, 2022 35 minutes ago, Oliver Morsch said: If you have the target server under control, then you can configure CORS there... It is a vendor-owned SMS gateway server so configuration control is out of the question. I am curious however. If Indy's TIdHttp or similar components can access the server and get a response code, why is it necessary to use complicated code and fiddle with CORS? Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 23, 2022 Share Posted July 23, 2022 19 minutes ago, Frederick said: If Indy's TIdHttp or similar components can access the server and get a response code Yes... Quote Link to comment Share on other sites More sharing options...
Oliver Morsch Posted July 23, 2022 Share Posted July 23, 2022 CORS is for security. So that no website can access the content of a foreign website. Quote Link to comment Share on other sites More sharing options...
Frederick Posted July 23, 2022 Author Share Posted July 23, 2022 9 minutes ago, Oliver Morsch said: CORS is for security. So that no website can access the content of a foreign website. Since the SMS gateway is a service site, the vendor allows anyone to access it. In fact, their API is published. Did they configure CORS to block access? Quote Link to comment Share on other sites More sharing options...
Oliver Morsch Posted July 23, 2022 Share Posted July 23, 2022 I think CORS is normally active by default. Maybe they can confirure your IP to be allowed. Quote Link to comment Share on other sites More sharing options...
Frederick Posted July 23, 2022 Author Share Posted July 23, 2022 16 minutes ago, Oliver Morsch said: I think CORS is normally active by default. Maybe they can confirure your IP to be allowed. The SMS gateway does have a IP whitelist option. If I specify one or more IP addresses to be whitelisted, only these IP addresses can access the gateway. I suppose this is the CORS configuration equivalent. Currently, I did not specify anything. So, any URL calls from my computer to the gateway should go through. Quote Link to comment Share on other sites More sharing options...
Oliver Morsch Posted July 23, 2022 Share Posted July 23, 2022 IP whitelist can be different from CORS list. You can see CORS in the header of the response. Quote Link to comment Share on other sites More sharing options...
Frederick Posted July 23, 2022 Author Share Posted July 23, 2022 Noted. Thanks. 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.