[play-2.1.1] jQuery multiple ajax calls conflicts - same Play controller called

150 views
Skip to first unread message

Anthony Legay

unread,
Jun 3, 2013, 10:19:09 AM6/3/13
to play-fr...@googlegroups.com
Hello there, I'm new here.
I'm currently developing an application with Play Framework 2.1.1 which uses AngularJS and (a lot of) ajax requests, sometimes at the same time.

In my angular controllers I'm calling several URLs at the same time to retrieve some data which are totally independent.

I'm doing something like this :

$http.get('/url1', function(res1){ $scope.res1 = res1; });
$http
.get('/url2', function(res2){ $scope.res2 = res2; });

What happens is that the result of the first call is overridden by the result of the second, or sometimes, the second overrides the first...
After a couple of refresh (about 30 or 40 times) I can say that the calls gave me the good results only 1 or 2 times !

The browser console says that a call to /url1 and /url2 is done correctly, but when I log the result in my Play controllers...the same controller is being called (with the two different URLs ! and that's why I think it's weird).
And when I say that the same controller is called, sometimes the first is called two times, sometimes the other is called two times...

Maybe I missed some important things with the Play configuration ?

Thanks in advance ! I really hope you can help me, because I'm stuck with this and this is rather critical...

Nilanjan Raychaudhuri

unread,
Jun 3, 2013, 11:20:12 AM6/3/13
to play-fr...@googlegroups.com
Show me your routes file?

Nilanjan, Developer & Consultant
Typesafe Inc.
Twitter: @nraychaudhuri

Anthony Legay

unread,
Jun 3, 2013, 11:50:58 AM6/3/13
to play-fr...@googlegroups.com
The routes file looks good, because when I call each url separately in the browser, or with a cURL command, I get the result that I want, and it is never corrupted.

Looks like this :

# ...
GET    
/url1        @controller.Resource1Controller.index()
GET    
/url2        @controller.Resource2Controller.index()
# ...

Sometimes, the Resource1Controller is called 2 times, sometimes, the Resource2Controller is called 2 times...then the same result is returned in each of the jQuery callback function, even if in the "Network" tab of the console, it says that /url1 and /url2 have been called.

Sorry, I know that I already said it but...I don't really know how to do better.
Reply all
Reply to author
Forward
0 new messages