简体   繁体   中英

call to WCF service from angularjs returns -1

I am using following code to call WCF service from angularjs. This function will be called on change of a textbox. HTML code :

<div><input type="text" placeholder="Search for items" id="textFiled" class="input" ng-keydown="checkKeyDown($event)" ng-keyup="checkKeyUp($event)" ng-model="searchText" ng-change="search()" /></div>

javascript code

//Function To Call On ng-change
    $rootScope.search = function () {
        var searchTextSmallLetters = angular.lowercase($scope.searchText);
        if (searchTextSmallLetters.length > 2) {

            $http({
                method: "GET",
                withCredentials: true,
                url: "http://XX.XXX.XX.XX:XX/Service.svc/Clients?prefix=" + searchTextSmallLetters,
                dataType: "json",
                headers: {
                    'Content-Type': 'application/json; charset=utf-8'
                }
            }).then(function successCallback(response) {
                if (response.status == 200) {
                    alert('success');
                }
                else {
                    alert('fail');
                }
            }, function errorCallback(response) {
                alert(response.status);
                alert('fail');
            });
        }
};

WCF operation contract for the service :

[OperationContract]
[WebGet(RequestFormat = WebMessageFormat.Json,ResponseFormat = WebMessageFormat.Json,UriTemplate = "/Clients?prefix={prefix}")]
List<string> GetClients(string prefix);

Function fails by giving alert message with status code "-1". When i check the same call in fiddler its returning the searched clients, with status code 200.

Hope someone can help me with this. Any suggestions or comments will be great. Thank you.

From memory, in past I got similar behavior (-1 status code) from js when:

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