I’m having a problem connecting to a php page using Ajax from my phone. I’ve simplified the transaction as much as possible. The server side code is:
<?php
echo(json_encode('success'));
?>
The client side code is:
$.ajax({
‘url’: "http://www.skynet.ie/~lobo/test.php",
‘success’: function(results){
alert(results);
},
‘error': function(XMLHttpRequest, textStatus, errorThrown) {
alert(JSON.stringify(XMLHttpRequest));
}
});
When testing from the Intel XDK emulator I get a successful response. When I launch the app from my phone (IOS) I get:
readyState: 0, responseText: ””, status: 0, statusText: ”error”
from the error function. I have tried adding
header('content-type: application/json; charset=utf-8');
header("Access-Control-Allow-Origin: *");
to the php page to no avail. I’ve set $.support.cors = true; locally. I’ve tried using the $.getJSON and just about every ajax option I could find that seemed relevant. I get a successful response connecting to http://time.jsontest.com from the phone and I can get a response from my own site in the emulator. I really don’t know what might be going wrong when I try connecting from the phone to the server. I’m thinking Any insights would be greatly appreciated.
Stephen