Hello All,
I am new to ionic. I was doing Matt’s weekly tutorial, ‘Using APIs with $http Part 1’.
I get the following error when I tried to POST into shettsu’s API. GET methods work. But, since its a server side error, I am finding it difficult to debug the code. Any insights on the error or even pointers to debugging tools would also help.
POST https://sheetsu.com/apis/v1.0/9d79fb258d0b 500 (Internal Server Error)
I found a few post on similar issues but couldn’t find a proper solution.
My Service looks like this. Exactly the same as http://docs.usecreator.com/docs/using-apis-with-http-part-1
angular.module('app.services', [])
.factory('BlankFactory', [function(){
}])
.service('Survey', ['$http', function($http){
var api_url = 'https://sheetsu.com/apis/v1.0/9d79fb258d0b';
var currentID = 1;
var ret = {
all: function(){
return $http.get(api_url).then(function(resp){
console.log(resp)
if (resp.data.length > 0) currentID = parseInt(resp.data[resp.data.length-1].id);
return resp.data;
});
},
add: function(data){
currentID++;
data.id = currentID;
return $http.post(api_url, data).then(function(resp){
return resp.data;
}
);
}
}
ret.all();
return ret;
}]);
Survey Page which makes the http call
// The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams, Survey,$ionicPopup) {
//Survey.all();
$scope.data = {
name:'',
favourite_colour:'Orange',
favourite_pizza:'Pepperoni'
}
$scope.submitting = false;
$scope.submit = function(){
$scope.submitting = true;
Survey.add($scope.data).then(function(){
$scope.data = {
name: '',
favorite_color: 'Orange',
favorite_pizza: 'Pepperoni'
}
$scope.submitting = false;
$ionicPopup.alert({
title: 'Thank you!',
template: 'Your response has been recorded.'
});
})
}
}
The error log on chrome dev tools
Request URL:https://sheetsu.com/apis/v1.0/9d79fb258d0b
Request Method:POST
Status Code:500 Internal Server Error
Remote Address:198.199.67.193:443
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
Access-Control-Allow-Credentials:true
Access-Control-Allow-Methods:GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD
Access-Control-Allow-Origin:https://creator.ionic.io
Access-Control-Expose-Headers:
Access-Control-Max-Age:1728000
Cache-Control:no-cache
Connection:keep-alive
Content-Length:39
Content-Type:application/json;charset=UTF-8
Date:Fri, 14 Jul 2017 20:47:14 GMT
Server:nginx
Vary:Origin
X-Request-Id:9ddcb967-bea0-43d7-a2a9-053811cd7e63
X-Runtime:0.803142
Request Headers
view source
Accept:application/json, text/plain, */*
Accept-Encoding:gzip, deflate, br
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Length:76
Content-Type:application/json;charset=UTF-8
Host:sheetsu.com
Origin:https://creator.ionic.io
Referer:https://creator.ionic.io/app/designer/9cb0b5d854e7
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36
Request Payload
view source
{name: "", favourite_colour: "Orange", favourite_pizza: "Pepperoni", id: 2}
favourite_colour
:
"Orange"
favourite_pizza
:
"Pepperoni"
id
:
2
name
:
""
Thanks in advance