Ios 10.3.2 upgrade does not allow communication with server

I have an app which I run on an iPhone. Recently, I updated the phone’s ios from 10.0.2 to 10.3.2. No changes were made to the app, but when I made the update it no longer works.

A short version of the app is as follows.

Function BtnCheckStatus_onclick()
req = Ajax(“http://***.../xampp/hello.php”)
LabelReq.textContent=req.status
If req.status = 200 Then
LabelAsusStatus.textContent="ASUS On-Line"
Else
LabelAsusStatus.textContent="ASUS Off-Line"
End If
End Function

As you can see, this app checks the status of a server (an ASUS laptop) and tells if it is on-line or off-line. The server contains a php file which responds to the app. Before the ios upgrade, this app worked - now it does not (it indicates that ASUS is Off-Line). I loaded the same app onto a different iPhone which is running an older ios and it worked fine (ASUS is On-Line with req.status of 200). It is obvious to me that something in ios 10.3.2 has changed and is not allowing my app to work.

Has anyone else had this problem with the new ios version? What do I need to change in my code?

Thank you!

Dick

We haven’t heard of other cases of this.

What value is being returned in req.status?

Hi George,

There is no value given for req.status. Only the “Off-Line” status is given (since req.status is not 200).

Dick

Can you modify your app so you see the value? It could be a clue as to the cause.

When I add the line “Print req.status” right after the “req=” line, it comes back with undefined.

Dick

What happens if you use https instead of http?

Then req.status comes back as 0. Still not 200.

0 is usually good too. Allow for both 0 and 200.

Ajax calls sometimes take a while. You can allow for this by separating the call from the response like this:

Function BtnCheckStatus_onclick()
	req = Ajax(”http://***.**..**/xampp/hello.php”,responseStatus)
End Function

Function ResponseStatus()
   If !req Then Exit Function
   If req.readyState<>4 Then Exit Function
   If req.status=200 Or req.status=0 Then
	LabelReq.textContent=req.status
	If req.status = 200 Then
	  LabelAsusStatus.textContent="ASUS On-Line"
	Else
	  LabelAsusStatus.textContent="ASUS Off-Line"
	End If
   Else
	alert(req.status)
   Endif
End Function

Helen

You can also limit the time for a response by using a SetInterval:

Function BtnCheckStatus_onclick()
  AjaxWaitTime = Now
  TW = SetInterval(responseStatus,250)
  req = Ajax(”http://***.../xampp/hello.php”)
End Function

Function ResponseStatus()
If !req Then Exit Function
If req.readyState<>4 Then 
  If DateDiff("s", AjaxWaitTime, Now) > 5 Then
    ClearInterval(TW)
    req.abort()
    LabelAsusStatus.textContent="5 second timeout"
  End If 
Exit Function
End IF
ClearInterval(TW)
If req.status=200 Or req.status=0 Then 
  LabelReq.textContent=req.status
  If req.status = 200 Then
    LabelAsusStatus.textContent="ASUS On-Line"
  Else
    LabelAsusStatus.textContent="ASUS Off-Line"
  End If
Else
  alert(req.status)
Endif
End Function

Helen makes a good point. It’s much better to make your calls asynchronous. It will make a better user experience and you won’t get nasty messages from Chrome saying synchronous calls are deprecated.

http://wiki.nsbasic.com/Ajax_made_Simple#Asynchronous_Calls

Hi John.

Thank you for your suggestions. I tried your code with the following results:

It worked correctly on my desktop computer, which is running NS Basic. It came back with ASUS On-Line and 200 as it should.

I then tried it on my older iPhone with an ios of 10.0.1. It also worked correctly.

When I tried it on my newer iPhone running ios 10.3.2, I got the “5 second timeout” message. When I checked the value of req.readyState, it came back as 1, not 4. I then changed your code to check if req.readyState<>1 instead of <>4, hoping that this would do it, but I got a message https://checkasusstatus-changes-wrongly.volt.live undefined. This link is my app I am running. All of this tells me that ios 10.3.2 is different is some way that is causing the problem. Note that it came back as 4 on my older iPhone.

Can you tell me what req.readyState represents? Should it always be 4? Also, it sure would be nice if you had an iPhone with ios 10.3.2 to try the code.

Thanks again for your help!

Dick

You might specify POST or GET to see if this makes a difference. I doubt it, but it’s worth a try.

req=Ajax”http://***…/xampp/hello.php”,“POST”) 'or “GET”

Also, could there be some setting on this phone that restricts Ajax POSTs? If you aren’t using Chrome try installing it on this phone and try it as well.

John

Did you try using https instead of http?

If you google ‘Ajax readyState’ you get the following responses:
0 = request not initialized
1 = server connection established
2 = request received
3 = processing request
4 = request finished and response is ready

If you test for ‘1’, all you know is that a connection has been made. You need to wait for ‘4’. If 5 seconds isn’t long enough, add some time.

Helen

Thanks for the info, Helen.

Dick