Rahul Rai

Rahul Rai

  • 1.6k
  • 149
  • 11k

Data not able to fetch from webservice in Angular

Feb 3 2020 4:28 AM
I am trying to fetch data from webservice but not able to do.
 
My code is:-
  1. login(){  
  2. console.log("Username:" +this.username);  
  3. console.log("Password:" +this.password);  
  4. var url = 'https://localhost:5125/WebService1.asmx' + '/HelloWorld';  
  5. let data1 = this.http.get(url);  
  6. data1.subscribe(data =>{  
  7. console.log('hello');  
  8. this.result = data;  
  9. this.navCtrl.push(RegisterPage,{text:this.password});  
  10. });  
  11. }  
and my webservice code is:-
  1. public int HelloWorld()  
  2. {  
  3. return 5;  
  4. }  
I am getting error:-
 
core.js:1449ERROR
HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: "http://localhost:5125/WebService1.asmx/HelloWorld", ok: false, …}
headers: HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ}
status: 200
statusText: "OK"
url: "http://localhost:5125/WebService1.asmx/HelloWorld"
ok: false
name: "HttpErrorResponse"
message: "Http failure during parsing for http://localhost:5125/WebService1.asmx/HelloWorld"
error:
error: SyntaxError: Unexpected token < in JSON at position 0 at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad (http://localhost:8100/build/vendor.js:79401:51) at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15660) at Object.onInvokeTask (http://localhost:8100/build/vendor.js:5125:33) at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15581) at r.runTask (http://localhost:8100/build/polyfills.js:3:10834) at e.invokeTask [as invoke] (http://localhost:8100/build/polyfills.js:3:16794) at p (http://localhost:8100/build/polyfills.js:2:27648) at XMLHttpRequest.v (http://localhost:8100/build/polyfills.js:2:27893)
stack: "SyntaxError: Unexpected token < in JSON at position 0↵ at JSON.parse (<anonymous>)↵ at XMLHttpRequest.onLoad (http://localhost:8100/build/vendor.js:79401:51)↵ at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15660)↵ at Object.onInvokeTask (http://localhost:8100/build/vendor.js:5125:33)↵ at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15581)↵ at r.runTask (http://localhost:8100/build/polyfills.js:3:10834)↵ at e.invokeTask [as invoke] (http://localhost:8100/build/polyfills.js:3:16794)↵ at p (http://localhost:8100/build/polyfills.js:2:27648)↵ at XMLHttpRequest.v (http://localhost:8100/build/polyfills.js:2:27893)"
message: "Unexpected token < in JSON at position 0"

Answers (2)