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) 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? 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. 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. 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? 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 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? 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. 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? 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. 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. 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 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. 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; 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? 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. 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... 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? 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... 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. 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? 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. 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. 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. Link to comment Share on other sites More sharing options...
Frederick Posted July 23, 2022 Author Share Posted July 23, 2022 Noted. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now