srinum
March 22, 2016, 10:25am
1
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",
srinum
March 24, 2016, 4:35am
3
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
A detailed discussion of what backend web frameworks are, why they are important, how they can ease things for devs, and the 10 best frameworks in 2023.
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
srinum
March 25, 2016, 6:20am
6
Thanks fretburner, for your kind suggestionsn it helped me overcome my problem
srinum
March 25, 2016, 6:22am
7
Thanks fretburner, for your kind suggestion about quotes it helped solve my problem
srinum
March 25, 2016, 6:23am
8
Thanks Mittineague, for taking time out to suggest
system
Closed
June 24, 2016, 1:23pm
9
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.