{"action":"created","issue":{"url":"https://api.github.com/repos/aspnet/jquery-ajax-unobtrusive/issues/19","repository_url":"https://api.github.com/repos/aspnet/jquery-ajax-unobtrusive","labels_url":"https://api.github.com/repos/aspnet/jquery-ajax-unobtrusive/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/aspnet/jquery-ajax-unobtrusive/issues/19/comments","events_url":"https://api.github.com/repos/aspnet/jquery-ajax-unobtrusive/issues/19/events","html_url":"https://github.com/aspnet/jquery-ajax-unobtrusive/issues/19","id":178781089,"number":19,"title":"Ajax redirect update","user":{"login":"RoySalisbury","id":12501943,"avatar_url":"https://avatars.githubusercontent.com/u/12501943?v=3","gravatar_id":"","url":"https://api.github.com/users/RoySalisbury","html_url":"https://github.com/RoySalisbury","followers_url":"https://api.github.com/users/RoySalisbury/followers","following_url":"https://api.github.com/users/RoySalisbury/following{/other_user}","gists_url":"https://api.github.com/users/RoySalisbury/gists{/gist_id}","starred_url":"https://api.github.com/users/RoySalisbury/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RoySalisbury/subscriptions","organizations_url":"https://api.github.com/users/RoySalisbury/orgs","repos_url":"https://api.github.com/users/RoySalisbury/repos","events_url":"https://api.github.com/users/RoySalisbury/events{/privacy}","received_events_url":"https://api.github.com/users/RoySalisbury/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/aspnet/jquery-ajax-unobtrusive/labels/wontfix","name":"wontfix","color":"ffffff"}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-09-23T04:16:46Z","updated_at":"2016-10-03T18:10:01Z","closed_at":"2016-10-03T18:10:01Z","body":"I like using ajax for my form submissions.  It allows me to update the page with the result for a nice user experience.\r\n\r\nHowever, sometimes you need to redirect to a new location and not just update the existing page.   In the past in my own ajax calls I used to \"unofficial\" status code of \"278\" for this.  This has been used for about 4 years in the community.  Its a \"success\" code so the browsers don't try to handle it.   Adding this functionality into the unobtrusive library is pretty simple.\r\n\r\nIn the \"asyncRequest\" method, I just updated the \"success\" function to:\r\n\r\n    success: function (data, status, xhr) {\r\n        if (xhr.status === 278)\r\n        {\r\n            var location = xhr.getResponseHeader(\"Location\") || window.location.href;\r\n            window.location.replace(location);\r\n\r\n            return;\r\n        }\r\n        asyncOnSuccess(element, data, xhr.getResponseHeader(\"Content-Type\") || \"text/html\");\r\n        getFunction(element.getAttribute(\"data-ajax-success\"), [\"data\", \"status\", \"xhr\"]).apply(element, arguments);\r\n    },\r\n\r\nThen you just have to return a status code 278 with a \"Location\" header containing the Url of the redirect.  Works great.  \r\n\r\nMight be worth adding to the base library.\r\n\r\nA second options (that requires no library update) is to return a \"278\" status code, with the \"Location\" header, but ALSO set the \"Content-Type\" to \"application/x-javascript\".  The library has a check for this in the \"asyncOnSuccess\" and will NOT run the \"success\" logic.  But it WILL run the \"data-ajax-complete\" method.  Then you can add your own status code \"278\" check and do the redirect.\r\n\r\nI like the first option .. seems cleaner.\r\n"},"comment":{"url":"https://api.github.com/repos/aspnet/jquery-ajax-unobtrusive/issues/comments/251180878","html_url":"https://github.com/aspnet/jquery-ajax-unobtrusive/issues/19#issuecomment-251180878","issue_url":"https://api.github.com/repos/aspnet/jquery-ajax-unobtrusive/issues/19","id":251180878,"user":{"login":"Eilon","id":202643,"avatar_url":"https://avatars.githubusercontent.com/u/202643?v=3","gravatar_id":"","url":"https://api.github.com/users/Eilon","html_url":"https://github.com/Eilon","followers_url":"https://api.github.com/users/Eilon/followers","following_url":"https://api.github.com/users/Eilon/following{/other_user}","gists_url":"https://api.github.com/users/Eilon/gists{/gist_id}","starred_url":"https://api.github.com/users/Eilon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Eilon/subscriptions","organizations_url":"https://api.github.com/users/Eilon/orgs","repos_url":"https://api.github.com/users/Eilon/repos","events_url":"https://api.github.com/users/Eilon/events{/privacy}","received_events_url":"https://api.github.com/users/Eilon/received_events","type":"User","site_admin":false},"created_at":"2016-10-03T18:10:01Z","updated_at":"2016-10-03T18:10:01Z","body":"Hi, this is an interesting feature request but given that it depends on non-standard behavior we feel it is not a good fit for the framework."}}
{"actor":{"display_login":"Eilon"}}