[英]How to decode url from ajax response?
在token.php
里面我有這個代碼:
$url = file_get_contents($urlPost);
preg_match('/\"amplem\":"(.*)\",/', $url, $matches);
echo $matches[1];
這個echo $matches[1]
將打印出一個這樣的網址:
https://example.com/?id\=g596c2f91a67e518\&itag\=18\&source\=test
。
在index.php
我做了一個 ajax 調用:
$.ajax({
type:'post',
url:siteURL+'/token.php',
data:{token:token},
success:function(data){
var i = decodeURIComponent(data);
console.log(i);
}
})
console.log(i)
當前結果:
https://example.com/?id\=g596c2f91a67e518\&itag\=18\&source\=test
。
console.log(i)
的console.log(i)
結果:
https://example.com/?id=g596c2f91a67e518&itag=18&source=test
。
編輯 -如果我將編碼的 url 直接放在decodeURIComponent();
我得到了想要的結果,但它不適用於從 ajax 調用返回的 url。
將unescape
與JSON.stringify
一起JSON.stringify
:
var i = "https://example.com/?id\=g596c2f91a67e518\&itag\=18\&source\=test"; console.log(unescape(JSON.stringify(i)));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.