I am trying to fetch data from webservice but not able to do.
My code is:-
- login(){
- console.log("Username:" +this.username);
- console.log("Password:" +this.password);
- var url = 'https://localhost:5125/WebService1.asmx' + '/HelloWorld';
- let data1 = this.http.get(url);
- data1.subscribe(data =>{
- console.log('hello');
- this.result = data;
- this.navCtrl.push(RegisterPage,{text:this.password});
- });
- }
and my webservice code is:-
- public int HelloWorld()
- {
- return 5;
- }
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"