繁体   English   中英

Angular JS $ http 404调用WebApi

[英]Angular js $http 404 call WebApi

我正在尝试使用“ $ http”调用我的网络服务。 如果调用“ $ ajax”可以正常进行。

示例Jquery $ Ajax工作正常。

$.ajax({
        type: "Get",
        crossDomain: true,
        contentType: "application/json; charset=utf-8",
        url: "http://localhost:60237/api/Get/Work",
        data: { cdUser: 1},
        dataType: "json",
        success: onDataReceived,
        error: onDataError
    });
    function onDataReceived(data) {
    }
    function onDataError() {
    }

示例角$ htpp(不起作用)

app.controller('alertxxController', function ($scope, $http) {

    $http({
        method: 'GET',
        url: 'http://localhost:60237/api/Get/Work',
        params: 'cdUser=1'
    }).success(function (data) {
        alert("ok");
    }).error(function () {
        alert("error");
    });



});

真的不知道为什么不这样打电话。 我无法识别错误,返回404(未找到)。

我认为您的“参数”选项是错误的。

尝试这个:

$http({
        method: 'GET',
        url: 'http://localhost:60237/api/Get/Work',
        params: { cdUser: 1}
    }).success(function (data) {
        alert("ok");
    }).error(function () {
        alert("error");
    });
});

我认为$ http在angular中的语法是

$http.get('url here').success(function (response) {}).error(function () {});

暂无
暂无

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

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