Firstly, never reload your page before you are sure that the ajax has completed its process.
Secondly, if you want to sort using JS run that code after you finish submitting the form or data in your case.
Here is how your ajax code with page reload on compeletion will look like
$.ajax({
type: 'GET',
url: 'your_page_link.php',//this will be url of your backend page
data: {
'name':name
'email':email
},// if you are using form then just use .serialize() to submit the form instead of preparing data like this use $("#form_id").serialize()
success: function (msg) {
resp = msg;
}
}).done(function(){
if(resp == your_expected_response){
window.location.href = "http://stackoverflow.com";
}else{
//your error handler
}
});
Hope this will be helpful, please feel free to ask if any clarification is required..
Cheers!!