Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<script>
window.hq.postDialog = function(form){
var params = hq.serialize(form);
var center = hq.initDialog();
window.hq.post(form.action, center, params);
};
// General post ajax method
window.hq.post = function(url, el, params){
if(!el){ el = document.getElementById('content');}
hq.ajax(url, {
method:'post',
data: params,
success: function(data){
if(data === ''){
// Redirect based on the response and where you came from
var redirect = cookies.get('redirect');
if(redirect){
window.location.href = redirect;
} else {
window.location.reload(true);
}
} else if(data[0] === '/'){
// Redirect to URL
// window.location.replace(data);
window.location.reload(true);
} else {
// No redirect, just update current page
el.innerHTML = data;
if(!dialogOpen()){ scrollTo(0, 0)};
loadScripts();
}
}
});
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.