MusicsCordova
MusicsCordova

Reputation: 222

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).

Upvotes: 0

Views: 414

Answers (2)

Ikechi Michael
Ikechi Michael

Reputation: 489

I think the syntax for $http in angular is

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

Upvotes: 0

Giuseppe Pace
Giuseppe Pace

Reputation: 156

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

Upvotes: 1

Related Questions