user1273357
user1273357

Reputation:

jquery ajax call in confirm button

Hi I written the ajax call inside if(confirm.... condition but it is not going to my ajax page. If i write $.get outside of if(confirm(.... then it is working fine.

What is the problem. please tell me some one.

function ConfirmSave() {    
    if (confirm("Do You Want to Save the test?")) 
    {          
        $.get('../Common/Ajax.aspx',{action:"UpdateExamDuration",UserExamMapID:UserExamMap});        
    }                
    document.location.href = "../Reports/Report-Card.aspx";       
}

Upvotes: 0

Views: 325

Answers (1)

LeonardChallis
LeonardChallis

Reputation: 7783

Ignoring the trailing brace } (probably just left that in there, right?) it worked for me, in that the ajax request was fired. I saw this because I had persist mode on in FireBug (meaning that request was still visible after I was redirected with the last line). What you want to do is put the document.location.href inside the $.get callback, meaning it will only run once it has completed:

if (confirm("Do You Want to Save the test?")) 
    {          
        $.get('../Common/Ajax.aspx', {action:"UpdateExamDuration",UserExamMapID:UserExamMap}, function(data){document.location.href = "../Reports/Report-Card.aspx";});        
    }                
}

Upvotes: 1

Related Questions