jquery リダイレクトURL取得

使う人おるのかな

OAuthでリダイレクトURL返ってきたときに後ろについてる認可コード取得したい場合
下記でとれる。

結局別のやり方にしたので以降は試してないけどハンドリングはできるんでないかと思う。

$.ajax({
    type: 'POST',
    url: 'http://localhost:15000/login',
    headers: {'Accept': 'application/json'},
    cache: false,
    dataType: 'text',
    xhrFields: {withCredentials: true},
    data:{mailaddr: 'aaaa@aa.@@', password: 'pass',  redirect_uri: 'http://localhost:5000/auth'},
    complete:function(){
        console.log(xhr.responseURL);
        code = getParam('code',xhr.responseURL);
        console.log(code);
        $('#msg').html(code);
    },
    xhr:function(){return xhr = new window.XMLHttpRequest();},
    error: function(data) {
        console.log("エラー");
    }
});

function getParam(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}