The Blog

Slick way to deal with 301 and 302 from Ajax call. Posted on

On the Server side response with similar code:

header('HTTP/1.0 278 Ok');
echo json_encode(array('redirect' => "/"));
exit;

In JQuery bind AjaxSuccess to this function. Somewhere in a global header or layout page, so it get accesses from all pages.

$('body').bind('ajaxSuccess',function(event, request, settings){
if (request.status == 278){
jsonresponse = $.parseJSON(request.responseText);
$('form').dirtyForms('setClean');
window.location.href = jsonresponse.redirect;
}
});
This entry was posted in PHP. Bookmark the permalink.

Please Post Your Comments & Reviews

Your email address will not be published. Required fields are marked *



CAPTCHA
Change the CAPTCHA codeSpeak the CAPTCHA code