最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - %2F instead of slash in url? - Stack Overflow

programmeradmin1浏览0评论

I have a problem with jquery syntax in an url link:

this is the link i am getting (englisch):

...myaccount/?lang=en%2Fprint-order%2F2067%2F&print-order-type=receipt

this is the german link:

...myaccount/print-order/2067/?print-order-type=receipt

the problem now is, that the link looks ok in my browser

myaccount/print-order/2067/?print-order-type=receipt

but actually there's always a "%2F" instead of a "/" inside the link when I copy it which leads to the problem of getting an 404.

When I manually replace "%2F" the link works.

Where is the problem? Any idea to fix this?

The code below comes from woocommerce/templates/myaccount/my-orders.php

if ($actions) { foreach ( $actions as $key => $action ) { echo '<a
 href="' . esc_url( $action['url'] ) . '" class="button ' .
 sanitize_html_class( $key ) . '">' . esc_html( $action['name'] ) .
 '</a>'; }

It generates the "Print" button on the "my orders" page. I am using mqtranslate german/englisch. In the german version everything works- the links are correct, ony when i switch the language there are "%2f" instead of "/". But also only after the first part (until myaccount/) - because some "/" are correctly encoded.

Also in the english version it's a "&" before "print-order-type=receipt" instead of a "?".

I have a problem with jquery syntax in an url link:

this is the link i am getting (englisch):

...myaccount/?lang=en%2Fprint-order%2F2067%2F&print-order-type=receipt

this is the german link:

...myaccount/print-order/2067/?print-order-type=receipt

the problem now is, that the link looks ok in my browser

myaccount/print-order/2067/?print-order-type=receipt

but actually there's always a "%2F" instead of a "/" inside the link when I copy it which leads to the problem of getting an 404.

When I manually replace "%2F" the link works.

Where is the problem? Any idea to fix this?

The code below comes from woocommerce/templates/myaccount/my-orders.php

if ($actions) { foreach ( $actions as $key => $action ) { echo '<a
 href="' . esc_url( $action['url'] ) . '" class="button ' .
 sanitize_html_class( $key ) . '">' . esc_html( $action['name'] ) .
 '</a>'; }

It generates the "Print" button on the "my orders" page. I am using mqtranslate german/englisch. In the german version everything works- the links are correct, ony when i switch the language there are "%2f" instead of "/". But also only after the first part (until myaccount/) - because some "/" are correctly encoded.

Also in the english version it's a "&" before "print-order-type=receipt" instead of a "?".

Share Improve this question edited Jun 11, 2014 at 14:27 ad2003 asked Jun 11, 2014 at 14:02 ad2003ad2003 3231 gold badge3 silver badges12 bronze badges 5
  • Don't really know what effect jquery or javascript has on your URL problem? – xate Commented Jun 11, 2014 at 14:04
  • 2 Show the jQuery code you are using. – Rudy Commented Jun 11, 2014 at 14:05
  • yeah sorry, maybe it's not jquery problem - I thought so first. I added code from the file, where it is generated – ad2003 Commented Jun 11, 2014 at 14:10
  • In the first url it looks like you have 2 query strings: myaccount/?lang=en%2Fprint-order%2F2067%2F?print-order-type=receipt. It looks as if the second url print-order/2067/?print-order-type=receipt was appended to myaccount/?lang=en – Daniel J.G. Commented Jun 11, 2014 at 14:13
  • Hi Daniel, yes, that's true - I am using mqtranslate and removed this code with jquery - "href.replace" that's why I first tought it has something to do with jquery. But it hasn't. I think it is this "esc_url" - but I don't know where to change this. Neither it has really something to do with this... – ad2003 Commented Jun 11, 2014 at 14:15
Add a comment  | 

2 Answers 2

Reset to default 13

Use decodeURIComponent on the copied value:

decodeURIComponent('myaccount/?lang=en%2Fprint-order%2F2067%2F?print-order-type=receipt')

http://jsfiddle.net/7hySU/

do this:

echo '<a href="' . urldecode($action['url'] ) ....

More about this: https://www.php.net/manual/en/function.urldecode.php

urldecode() is doing egzactly what you are looking for. Just apply it in your foreach loop.

This will solve your problem

Cheers :)

You can try it at http://3v4l.org/mhVuV kind of phpfiddle :)

put this in the box:

    echo urldecode("myaccount/?lang=en%2Fprint-order%2F2067%2F&print-order-type=receipt");
发布评论

评论列表(0)

  1. 暂无评论