I’m just trying to make a get request to to the Couchbase API in a skeleton Cordova/iOS application and I am getting a failure response. I’ve tried using coax, jQuery.Ajax and plain XMLHttpRequest and am having the same poor luck.
index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<!-- STYLES -->
<style>
@font-face {
font-family: 'Montserrat';
src: url('./Fonts/Montserrat-Regular.otf') format("opentype");
}
</style>
<script src="cordova.js"></script>
<script src="http://code.jquery.com/jquery-2.1.4.min.js" type="text/javascript"></script>
<script>
function loadApp() {
// see http://stackoverflow.com/questions/23662121/cordova-plugins-only-work-in-ios-the-second-time-its-opened-with-a-thread-warnin
// cordova.exec.setJsToNativeBridgeMode(cordova.exec.jsToNativeModes.XHR_NO_PAYLOAD);
cbliteTest();
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'main.js';
head.appendChild(script);
}
function cbliteTest() {
if (!window.cblite) {
console.log('CBLite plug-in not found');
return;
}
console.log('CBLite plug-in found');
window.cblite.getURL(function (err, url) {
if (err) {
console.log('Unable to find CBLite API: ' + JSON.stringify(err));
return;
}
console.log('CBLite API found at: ' + url);
$.ajax({
type: 'GET',
url: url + '_all_dbs',
beforeSend: function(xhr, contents) {
console.log('beforeSend-xhr: ' + JSON.stringify(xhr));
console.log('beforeSend-contents: ' + JSON.stringify(contents));
},
success: function (data, status, xhr) {
console.log('success-xhr: ' + JSON.stringify(xhr));
},
error: function (xhr, status, error) {
console.log('error-xhr: ' + JSON.stringify(xhr));
}
});
//var xhr = new XMLHttpRequest();
//xhr.open('GET', url);
//xhr.onreadystatechange = function () {
// console.log('State: ' + xhr.readyState);
//};
//xhr.onload = function () {
// console.log('Success: ' + JSON.stringify(xhr));
//};
//xhr.onerror = function () {
// console.log('Error: ' + JSON.stringify(xhr));
//};
//xhr.send();
});
}
document.addEventListener("deviceready", loadApp, false);
</script>
</head>
<body style="font-family: 'Montserrat';">
<div id="app"><!-- CONTENT --></div>
<!-- DATA -->
</body>
</html>
When I run the application in XCode, I get the following feedback:
2015-06-03 12:28:02.447 Smart Kennel[13445:412742] DiskCookieStorage changing policy from 2 to 0, cookie file: file:///Users/Stephen/Library/Developer/CoreSimulator/Devices/6DE60716-CAFD-4981-9F62-6C0AA5534C50/data/Containers/Data/Application/A104152D-BEA9-4476-B7F5-007C4BA98DC8/Library/Cookies/Cookies.binarycookies
2015-06-03 12:28:02.471 Smart Kennel[13445:412742] Apache Cordova native platform version 3.8.0 is starting.
2015-06-03 12:28:02.472 Smart Kennel[13445:412742] Multi-tasking -> Device: YES, App: YES
2015-06-03 12:28:02.473 Smart Kennel[13445:412742] Unlimited access to network resources
2015-06-03 12:28:02.599 Smart Kennel[13445:412742] Using a WKWebView
2015-06-03 12:28:02.698 Smart Kennel[13445:412742] [CDVTimer][statusbar] 13.449013ms
2015-06-03 12:28:02.698 Smart Kennel[13445:412742] Launching Couchbase Lite...
2015-06-03 12:28:02.704 Smart Kennel[13445:412742] Couchbase Lite url = http://lite.couchbase./
2015-06-03 12:28:02.704 Smart Kennel[13445:412742] [CDVTimer][cblite] 6.072998ms
2015-06-03 12:28:02.705 Smart Kennel[13445:412742] [CDVTimer][TotalPluginStartup] 19.801021ms
[INFO] GCDWebServer started on port 12344 and reachable at http://10.12.0.107:12344/
2015-06-03 12:28:02.707 Smart Kennel[13445:412742] Started http daemon: http://10.12.0.107:12344/
2015-06-03 12:28:03.063 Smart Kennel[13445:412742] CBLite plug-in found
2015-06-03 12:28:03.067 Smart Kennel[13445:412742] CBLite API found at: http://lite.couchbase./
2015-06-03 12:28:03.070 Smart Kennel[13445:412742] beforeSend-xhr: {"readyState":0}
2015-06-03 12:28:03.073 Smart Kennel[13445:412742] beforeSend-contents: {"url":"http://lite.couchbase./_all_dbs","type":"GET","isLocal":false,"global":true,"processData":true,"async":true,"contentType":"application/x-www-form-urlencoded; charset=UTF-8","accepts":{"*":"*/*","text":"text/plain","html":"text/html","xml":"application/xml, text/xml","json":"application/json, text/javascript","script":"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},"contents":{"xml":{},"html":{},"json":{},"script":{}},"responseFields":{"xml":"responseXML","text":"responseText","json":"responseJSON"},"converters":{"text html":true},"flatOptions":{"url":true,"context":true},"jsonp":"callback","dataTypes":["*"],"crossDomain":true,"hasContent":false}
2015-06-03 12:28:03.269 Smart Kennel[13445:412742] error-xhr: {"readyState":0,"status":0,"statusText":"error"}
2015-06-03 12:28:03.272 Smart Kennel[13445:412742] error-error: ""
I have found a few instances of people reporting similar results in various forums, but it seems in most cases they were not getting the correct URL. As far as I can tell, the request url here is legit. Anyone have any ideas?