I have a cordova project in Visual Studio. I need server data which I get by making ajax GET requests. I have fixed CORS issues by adding the meta tag
<meta http-equiv="Content-Security-Policy" .../>
and my back-end server also responds to CORS requests because I added this line to my web.config:
<add name="Access-Control-Allow-Origin" value="*" />
My setup WORKS in simulation and on devices for both iOS and Android.
Now I need to do my first Windows app. When I change to build for Windows 10, in debug mode the app never gets any data from the server.
This is my observations:
- The server does not receive any request from the app.
- When I press F12 and look at the Network Tab, the request is marked with status 200, although the request is not registered at the server.
- If I start Fiddler, the app starts to receive data, meaning data is returned to every request.
This screenshot is of the Developer Tools. I press a Refresh button in the app. First 2 entries are made without Fiddler running. Next I start Fiddler and now data is returned. I noticed the "(From Cache)" in the "Received" column, but clicking the "clear cache" button (in dev. tools) does not remove the problem.
Are there any special settings that I might not have set for Windows in Cordova?
Edit: Here is some simple source that fails in the same maner. To Reproduce, create a blank Cordova project in Visual Studio, add jQuery, and deploy.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' 'unsafe-inline' data: * gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
<title>WinApp</title>
<script src="scripts/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
function ajaxReq() {
$.ajax({
type: 'GET',
url: 'http://192.168.1.79/',
dataType: 'json',
success: function (msg, status, jqXHR) {
alert('it worked')
return true;
},
error: function (jqXHR, exception) {
alert('it failed')
return false;
},
timeout: 30000
});
}
</script>
</head>
<body>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="scripts/platformOverrides.js"></script>
<script type="text/javascript" src="scripts/index.js"></script>
<button onclick="ajaxReq(); return false;">click me</button>
</body>
</html>
The posted code works if running as a browser simulation for iOS and Android. It fails on Local Machine for Windows builds (x86 & x64).
