views:

62

answers:

0

I have a a button (not a submit button) which does ajax calls before submitting another form.

What I want to do is

Given I am viewing homepage
When I press "JustAButton"
Then I should be on "/users/home"

But the redirection happens somewhat late and "Then" statement fails considering that the page is still in homepage. How can I wait till the ajax calls (that result from clicking the button) are finished and the page gets submitter??

Any ideas?

EDIT : Sample javascript code

For

<input type="button" id="btn_Send" value="Send"/>

Javascript is (pls ignore the syntax errors, I think you would get the overall idea)

document.ready(){
$("#btn_Send").click(function(){
   ajax.post('some url',<params>, callbackForSuccess);
}

function callbackForSuccess(result){
   $("#form1").submit();
}