2016-11-26 86 views
0

有人做了一個網頁,從Eventbrite在線上售票拉事件數據,並將其寫入了SVG,使用亞馬遜Web服務,並將其保存爲PDF創建傳單。數字符號/井號(#)打破代碼

它在這裏工作:www.ilovemylaser.com/fliers.html。

但是,如果我在地址欄中使用'#',它會中斷,因此對於聖地亞哥的情況,我已將'#'替換爲'否'。

如果你看一下www.admaticonsulting.com/resources/fliers2.html,我用 '#2'。如果您點擊傳單,您會看到城市,地點名稱,時間,州和郵編都丟失了。將它與第一個鏈接中的千橡木傳單進行比較。

此行的代碼,我敢肯定它的問題:

var output = "<p><a href=\"h t t p ://ec2-52-42-194-56.us-west-2.compute.amazonaws. com/task.php?date=" + date + "&staddress=" + venue + "&venue=" + ven3 + "&city=" + city + "&region=" + region + "&postal_code=" + postal_code +"&time="+ time + "\">" + date + " - " + city + "</a><br></p>"; 

現在我不能發佈超過2個鏈接,但如果你點擊任何鏈接飛,你會看到它會顯示一個鏈接,然後解決另一個。

很確定#正在影響這個。此外,在有「#」的「已解決的鏈接」中有空格。有沒有在做的那些空格不

如何,我可以使用#,而不是對飛行物丟失的數據?

回答

0

URL中的#開始Fragment Identifier,由瀏覽器或其他客戶端本地處理;它是不包含在發送給服務器的HTTP請求中,因此不能用於服務器上的任何處理。 To include a 'reserved' character as data in a URL you must encode it。請注意,鏈接是https://en.wikipedia.org/wiki/Percent-encoding#Percent-encoding_reserved_characters,當您單擊它時,從服務器獲取的頁面是https://en.wikipedia.org/wiki/Percent-encoding,那麼您的瀏覽器將定位到Percent-encoding_reserved_characters的定位標記。

+0

我現在還記得,我用之前。謝謝。 – user3655385

1

您需要使用encodeURIComponent編碼每個查詢字符串值:

var output = "<p><a href=\"h t t p ://ec2-52-42-194-56.us-west-2.compute.amazonaws. com/task.php?date=" + encodeURIComponent(date) + "&staddress=" + encodeURIComponent(venue) + "&venue=" + encodeURIComponent(ven3) + "&city=" + encodeURIComponent(city) + "&region=" + encodeURIComponent(region) + "&postal_code=" + encodeURIComponent(postal_code) +"&time="+ encodeURIComponent(time) + "\">" + date + " - " + city + "</a><br></p>"; 
+0

這很有道理,謝謝 – user3655385