Programming with $http service in Angularjs is not giving desired result

Following code using $http service in Angularjs is not giving required output:

$http({
                url: ' "http://localhost/AdvancersService/AdvancersService.svc/GetDomains" ',
                method: "POST",
                data: { "name": { "SearchText": "Info" } },
                
            })
                    .then(function (response) {
                        // success
                        alert("Success:" + response)
                       
                    },
                    function (response) {
                        // failed
                        
                        alert("Failed" + response)
                    });

please suggest to make code operate, any suggestion will be appreciated.

Hi srinum,

It’s easier for people to help you if you can be more specific about your problem: what is the actual output from the code vs the result that you want to achieve?

Looking at your code, your URL string is wrapped in both double and single quotes:

 url: ' "http://localhost/AdvancersService/AdvancersService.svc/GetDomains" ',

should be:

url: "http://localhost/AdvancersService/AdvancersService.svc/GetDomains",

Hi fretburner,

I am srinum in the above code I pasted
“alert(“Failed” + response)” is returning as
“Failed Object”

“Object” is because that is what “response” is.
You will likely want one or more of its properties.

Here’s an example

You can get the response status by changing your alert call to:

alert(response.statusText);

although it would be better to use console.log(response) to output the response object to the brower’s console where you can examine it more easily.

1 Like

Thanks fretburner, for your kind suggestionsn it helped me overcome my problem

Thanks fretburner, for your kind suggestion about quotes it helped solve my problem

Thanks Mittineague, for taking time out to suggest

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.