简体   繁体   中英

Angular js $http 404 call WebApi

I'm trying to call my webservice using "$http". if call with "$ajax" working ok.

Example Jquery $Ajax working ok.

$.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() {
    }

Example Angular $htpp (Not Working)

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");
    });



});

Really do not know why not this calling. I can't identify the error, return 404 (Not Found).

I think your "params" option is wrong.

Try this:

$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 () {});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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