Skip to content

Instantly share code, notes, and snippets.

@crowdfundhq
Created January 4, 2019 03:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save crowdfundhq/f34044cf5604c0dea368964cdeb5d801 to your computer and use it in GitHub Desktop.
Save crowdfundhq/f34044cf5604c0dea368964cdeb5d801 to your computer and use it in GitHub Desktop.
<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