2016-11-26 49 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