在按下按钮时调用包含“$http.get()”的函数

在按下按钮时调用包含“$http.get()”的函数,http,angularjs,angularjs-service,Http,Angularjs,Angularjs Service,调用包含$http.get()的函数 我正在从ng单击调用函数 <input type="submit", value='ask', ng-click='storeDb()'/> 警告消息为错误为0向添加另一个函数,然后处理程序处理错误情况,并调试或记录输出。尽管我相信jkschneider是正确的,但您似乎确实有错误,调试它应该可以帮助您找到问题,我可以指出两个错误吗 首先是对th$http.get的滥用,它应该是这样的 $http({ method: 'GET',

调用包含
$http.get()的函数

我正在从
ng单击调用函数

<input type="submit", value='ask', ng-click='storeDb()'/> 


警告消息为
错误为0

添加另一个函数,然后
处理程序处理错误情况,并调试或记录输出。

尽管我相信jkschneider是正确的,但您似乎确实有错误,调试它应该可以帮助您找到问题,我可以指出两个错误吗

首先是对th$http.get的滥用,它应该是这样的

$http({
    method: 'GET', url: '/someUrl'}).
      success(function(data, status, headers, config) {
        // this callback will be called asynchronously
        // when the response is available
      }).
      error(function(data, status, headers, config) {
        // called asynchronously if an error occurs
        // or server returns response with an error status.
      });
也可以类似于$http.get().success().error()

请看这里。$http


其次,您应该使用MVVM/MVC方式获取/更新应用程序中的数据(即,您需要一个模型),否则您可能会遇到其他一些问题。我写了一篇简短的教程,其中包含完整的代码示例

有关错误或不正确的url,请参阅浏览器控制台日志和网络选项卡。使用浏览器控制台检查请求…需要比处理请求时提供的更多详细信息。“让我回去。”钱德尔马尼做了一些诊断。还是拿不到。出现错误,但状态为
0
@charlietfl进行了一些诊断。还是拿不到。出现错误,但状态为0。执行了一些诊断。还是拿不到。出现错误,但状态为0
$http({
    method: 'GET', url: '/someUrl'}).
      success(function(data, status, headers, config) {
        // this callback will be called asynchronously
        // when the response is available
      }).
      error(function(data, status, headers, config) {
        // called asynchronously if an error occurs
        // or server returns response with an error status.
      });