Q: flow of agentcall in javascript

I am using JS to launch an agent that manipulates a shopping basket.

(I inherit the app so I am stuck with current look)

This is the code:

} else {

	result = runAgent("", BuildXMLVariables("prepareForOffer", sessionID, ProductID, ProductQty)); 

	window.location.href = dbPath + "PCOrder?OpenForm&"+sessionID

}

The agent then recalculates certain order values and then saves the basket-document.

But I am suspecting that the flow is corrupted. The second line (window.location.href) is triggered and the page openes. But the agent is not done yet.

I know the more smarter way would be to let the agent set location. But I wonder if there is a simple way to validate this flow?

Subject: Q: flow of agentcall in javascript

Can you put your ‘window.laction’ call in a loop that looks for something set at the very end of the agent. Something like:

While booleanVariableName <> True

 window.location

Wend

Then ‘set booleanVariableName = True’ at the end of your agent?

Shawn

Subject: Q: flow of agentcall in javascript

Not knowing what either your runAgent() or BuildXMLVariables() are doing, I am guessing you are doing some asyncronous xmlHttpRequest stuff in there. If you are, then then that will be done on a separate thread (async, remember), and the normal flow of you code will continue without waiting for the runAgent() code to finish.

The proper way of handling it would be to specify a call-back function that would be called once the xmlHttpRequest finishes…

Or just run it syncronously… but that takes away much of the point of using ajax, if you ask me… :slight_smile:

Bjorn

Subject: RE: Q: flow of agentcall in javascript

Jupp. That’s correct.

The crap part is that I have inherit the code (and now the problem)… The “agent” calculates a lot of crap and then creates the page that is supposed to be loaded.

Which don’t exists when the URL.location is loaded.

Well… thx y’all for the input. I guess I have to find another solution. It’s such a stupid app… never use freelancing consultans :wink: