angular 2 http get request getting called twice, when the size of data is large

Multi tool use
angular 2 http get request getting called twice, when the size of data is large
I m trying to fetch history data for one month using angular http get request. I m using angular 5,server is in node js and db is mongodb.
On first click on button it hits the server and console is printed on server. After 2 mins again server consoles as ui hits server, but there is no call made by the ui to server. After 1 min, sent successful response is showed by server, but ui console displays like error-"connection refused". i tried to resolve it using share from observable. But it did not work
This is my service.
getReports(params): Observable<number>{
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
return this.http.get(url, options)
.map((res: Response) => res.json())
.catch(this.handleError)}
your tag says angularjs, but this is not angularjs... it's angular
– Comann Silvan
Jul 3 at 5:55
you have to increase response time. By default every technology will call request again if didn't received response after certain time.
– Ratan Uday Kumar
Jul 3 at 6:23
Thanks @RatanUdayKumar for your answer. How can i increase the response time in angular
– user2610
Jul 3 at 6:27
update my answer
– Ratan Uday Kumar
Jul 3 at 6:30
1 Answer
1
try like below
return this.http.get(url, options)
.timeout(3000, new Error('timeout exceeded'))
.map((res: Response) => res.json())
.subscribe(
data => this.data = data,
error => console.debug('ERROR', error),
() => console.log('END')
);
.catch(this.handleError)}
using timeout it is possible. 3000 means 3 secs or 3000 ms
i updated my answer @RatanUdayKumar. I gave response time as 120000 ie. 2 minutes. But still i can see the server is called again after 2 minutes.
– user2610
Jul 3 at 7:05
how many time thus server getting request not client side
– Ratan Uday Kumar
Jul 3 at 7:08
in angular in client side for every api there will be 2 request but server will get only 1 request
– Ratan Uday Kumar
Jul 3 at 7:09
2 times server is getting the request.
– user2610
Jul 3 at 7:11
how much time does server taking to send response
– Ratan Uday Kumar
Jul 3 at 7:12
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Any suggestion will be great help.
– user2610
Jul 3 at 5:43