I have an Ember application that is typically going to make ajax requests to a server to get its data. The issue I’m facing is that each request needs to have a signature appended to the URL. This signature needs to be calculated often as it is only valid for maybe 10 seconds. The system requires that I request this signature from a server, probably using an ajax request. So, my issue is that Ember can never use the signature returned from the ajax request because it’s not designed to wait around, as expected.
The code in question is here: http://jsfiddle.net/veDjq/
In that code, signature inside App.Post is always undefined though I can see that the request for the signature returns a correct value if I console.log the response in App.Signature.
I’m new to Ember so I am more than likely going about this wrong way. In the end, I need to be able to request a new signature each time an Ember object has to request data from the server. I’ve attempted to use jQuery’s $.ajaxSend to change the URL, but it doesn’t work on GET requests.
Inside of your
successhandler,thisis not what you think it is. It looks like you intend forthisto be theApp.Signatureclass. In order to make that the case, you can set thecontextoption of the signature ajax call tothis.I would also recommend looking into promises. They will help you clean up this code. For example (untested):