开发者

redirecting to URL while changing parent path in JavaScript

I have an url:

 http://domain/request.php?id=123

Now on this site I have a button with a submit handler that is supposed to redirect to

 http://domain/submit_solution#/?id=123

I tried this:

        $('#r_submit_form').click(function()
        {
               window.location = 'submit_soluti开发者_如何转开发on#/?id=' + $(this).attr('name');
        });

But instead of redirecting to

  http://domain/submit_solution#/?id=123

it just appends

 http://domain/request.php?id=123?123=Submit+solution

I have tried all kinds of variants with window.location.href.replace but I cant find a way to change the whole url and not just append another part to it. How can it be done?

The rewrite rule for request.php is

RewriteRule ^(request|profile|profile_picture|solution|payment)/([0-9]+)$     /$1.php?id=$2 [L] –


It appends because you should use the whole domain in your window.location:

    $('#r_submit_form').click(function()
    {
           window.location.href = 'http://domain/submit_solution#/?id=' + $(this).attr('name');
    });


window.location has the information you need:

    $('#r_submit_form').click(function()
    {
           window.location = window.location.origin + '/submit_solution#/?id=' + $(this).attr('name');
    });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜