Calling a web service

Hi guys,

I am using the following code:

indent preformatted text by 4 spaces
btnGetFile.onclick = function() {
req=Ajax("http://192.168.1.15:7777/?"  +  txtURL.value, done);
};

function done() {
if(req.status == 200) { //success
htmResponse.innerHTML=req.responseText;
} else { //failure
msg = "Error: Status = "  +  req.status;
if(TypeName(req.statusText)=="string" ) { msg = msg  +  " "  +  req.statusText; }
if(TypeName(req.err)=="string" ) { msg = msg  +  " "  +  req.error; }
NSB.MsgBox(msg);
}
}

The response is simply some text. If I put the url directly in the browser I get the text back okay.
In the app run in the browser I get:

Error: Status = 0 error

I see the request come into the web service.

What am I missing please.

You’ll want to inspect the web app as it is running under chrome (right click, last menu item). What you’ll probably see in the console window is an error about cross domain issues. You’ll want to look at posting on this board for content security policy. There are changes on the data server and within your app settings. They are outlined here in several threads.

Hi gary,

the web service in written in Delphi and a search revealed I need to add

with aResponseInfo do
        CustomHeaders.AddValue('Access-Control-Allow-Origin','*'); on 

procedure TForm7.IdHTTPServer1CommandGet event.

So I presume cross domain is allowed.
I cannot find anything in the forum with ref to the setting within app studio.

What do I need to do within the app please?

I have it working as above.
The issue was Safari wasn’t loading the latest version of the app with the remote ip.

Of course you will have to change the’’ in (‘access-control-allow-origin’, ‘’) to your actual domain otherwise you’re creating a security exploit.

And using another port number on a domain is considered cross domain. Content Security Policy in the app (project properties) and the access control allows origin on the server will need adjusting.

However, it may work today on some browsers without any settings as not all browsers have blocked all cross domain access, but it’s coming.

as i know,
ajax always return 0 when call a http url instead of https url

Hi,
Thanks for the reply. I worked it out that the link automatically used https.

I have ssl certs on my domain so I presume I have to setup ssl on the web service. This is a Delphi application.

I feel some learning pain coming on. :grin: