Javascript &引用;SyntaxError:意外标记<&引用;带离子角JS
我正在使用Angular JS调用CakePHP服务器上的API。它向MySQL数据库添加了一个新客户:Javascript &引用;SyntaxError:意外标记<&引用;带离子角JS,javascript,angularjs,cakephp,syntax-error,Javascript,Angularjs,Cakephp,Syntax Error,我正在使用Angular JS调用CakePHP服务器上的API。它向MySQL数据库添加了一个新客户: $scope.submitForm = function(isValid) { if (isValid) { $http({ method : 'POST', url : 'https://www.something.com/customers/add.json', data : $.param($sco
$scope.submitForm = function(isValid) {
if (isValid) {
$http({
method : 'POST',
url : 'https://www.something.com/customers/add.json',
data : $.param($scope.formData),
headers : { 'Content-Type': 'application/x-www-form-urlencoded' }
})
.success(function(data) {
console.log(data);
if (data.success == false) {
$scope.error = data.message;
} else {
$scope.message = data.message;
}
});
}
}
当添加新实体失败时,我得到正确答案(如果条件满足):
当可以添加实体时,我得到以下条件(否则条件):
为什么我总是得到else条件的语法错误?如注释中所述。。。这是因为成功响应不是有效的JSON
尝试在控制台中调试输出并进行相应的修复;-) 什么是
$this->Customer->invalidFields()代码>在成功案例中生成?看起来响应不是有效的JSON?即使我完全删除变量$reason
我也会得到相同的错误@AdamJeffers,成功和错误的JSON字符串几乎相同。几乎相同?在else块中注销data.message
时,您在控制台中看到了什么?没有,对于else条件,我只看到错误,根本没有控制台输出。
SyntaxError: Unexpected token <
at Object.parse (native)
at fromJson (http://localhost:8100/lib/ionic/js/ionic.bundle.js:10063:14)
at defaultHttpResponseTransform (http://localhost:8100/lib/ionic/js/ionic.bundle.js:18080:16)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:18171:12
at forEach (http://localhost:8100/lib/ionic/js/ionic.bundle.js:9168:20)
at transformData (http://localhost:8100/lib/ionic/js/ionic.bundle.js:18170:3)
at transformResponse (http://localhost:8100/lib/ionic/js/ionic.bundle.js:18926:23)
at processQueue (http://localhost:8100/lib/ionic/js/ionic.bundle.js:23399:28)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:23415:27
at Scope.$eval (http://localhost:8100/lib/ionic/js/ionic.bundle.js:24678:28)
if ($this->Customer->save($this->request->data)) {
$message = 'Adding customer was successful, thanks!';
$success = true;
} else {
$message = 'Adding customer failed, please try again.';
$success = false;
}
$this->set('_serialize', array('message', 'success'));
$this->set(compact('message', 'success'));