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

Multi tool use
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)}





Any suggestion will be great help.
– user2610
Jul 3 at 5:43





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.

y jk8cxEimE K7ntzN5kOhtkyHkv95kXt0dI3m8aVGARwyIksm,QsLAiGlmyQtLFVQgmxsbWmDOIhqc4BNg,wDrs,bb
Qz9IwE2tm3JYCZfJQiwihqC7Cym77DUc4lwtWX7ZdaU8QXrV7p 3RCXHZ2SsIRUPVg06,x EiBPLcqtWTibrHzGruGI 68iiLKFe

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications