I have 3 files in my folder.
- index.html ( contains HTML/AngularJS)
- controller.js ( contains angular app and functions calling my routes on my server )
- server.js ( contains my node/restify server and my connection to couchDB)
My Question:
I am trying to connect to CouchDB and access the database within to perform simple GET/POST/PUT/DELETE actions. When I run the code below I get the following errors (see image below).
The console.log(resData) outputs "undefined" and if you run the link http://ift.tt/1EdEUD4 you can see the data in your browser.
**
Can anyone please help me solve this. Is there anything I am doing wrong?
**
index.html
<!DOCTYPE html>
<html ng-app="myApp">
<head>
<script src="http://ift.tt/1zqtfiO"></script>
<script type="text/javascript" src="controller.js"></script>
<script type="text/javascript" src="server.js"></script>
</head>
<body ng-controller="couchCtrl">
<form ng-submit="submit()">
<p>Name:</p><input ng-model="name">
<button>Submit</button>
</form>
</body>
</html>
Controller.js
var myApp = angular.module("myApp", []);
myApp.controller("couchCtrl", ["$scope", "$http", function($scope, $http){
$scope.submit = function(){
var url = "http://ift.tt/1EdESLf";
$http({
url: url,
method: 'GET',
contentType: "application/x-www-form-urlencoded",
dataType: "json",
}).success(function(data, status, headers, config){
alert("AJAAX Returned!");});};
}]);
server.js
var restify = require("restify");
var nodeCouchDB = require("node-couchdb");
var server = restify.createServer();
var port = process.env.PORT || 8080;
var couch = new nodeCouchDB("smk.iriscouch.com");
server.listen(port, function(){
console.log("incoming requests");
});
server.get('/users', function(req, res){
couch.get("testbook", "_all_docs", function (err, resData) {
if (err) {
console.error(err);
}
console.log(resData);
});
console.log("Got it!");
res.end();
});
Aucun commentaire:
Enregistrer un commentaire