简体   繁体   English

$ http.post angularjs不会成功或出错

[英]$http.post angularjs do not get in to success or error

My code is like this 我的代码是这样的

$http.post("../services/myurl.aspx?Param=" + finaldata, '', { 'Content-type': 'text' })
.success(function (pricedata) {
    alert (success)                        
})
.error(function () {
    alert('we have failed to make a connection with the server. Please try after some time');
});

When I make this call neither success nor error happens.But the service is called. 当我进行此调用时,成功或错误都不会发生。但是会调用该服务。 I am a little confused. 我有点困惑。 can anyone point out what I am doing wrong? 谁能指出我做错了什么?

You should use service to post data, here is how you could do it. 您应该使用服务发布数据,这是您可以使用的方法。

doSomething: function (data, url) {
            return $http({
                url: url,
                method: 'POST',
                data: data
            });
        },

and in your controller consume this service as 并在您的控制器中将此服务作为

someService.doSomething($scope.MyData, $scope.Url)
        .success(function (response) {
            console.log("Success", response);
        })
        .error(function (data, status, headers, config) {
            console.log("Error");
        });

Try this simple code.... 试试这个简单的代码。

       $http({
            method: 'POST',
            url: "../services/myurl.aspx?Param=" + finaldata,
       })
      .success(function (data, status, headers, config) {
         var success="success"
          alert (success);// or alert("success")
       })
      .error(function (data, status, headers, config) {
           alert('we have failed to make a connection with server. Please try after some time');
       });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM