[英]How can I escape single quotes from get method in Javascript?
I am passing the form values via get method. 我通过get方法传递表单值。 Here is the url parameters.
这是url参数。
"name='test'&exp=&level=&gender=&city=&sports="
While getting the values from get method in javascript, single quote is getting as %27
. 从javascript中的get方法获取值时,单引号为
%27
。 How can I escape it? 我该如何逃脱呢?
while alerting $_GET("name")
, it gives %27test%27
. 在警告
$_GET("name")
,给出%27test%27
。
Please help 请帮忙
You should use php's urldecode on the value. 您应该在值上使用php的urldecode。 Docs found at http://php.net/manual/en/function.urldecode.php
可在http://php.net/manual/zh-CN/function.urldecode.php找到文档
Let me know if that's what you're looking for :) 让我知道您是否在寻找:)
Replace : 更换:
"name='test'&exp=&level=&gender=&city=&sports="
To 至
"name=test&exp=&level=&gender=&city=&sports="
or 要么
Use: 采用:
var decoded = unescape(url);
or 要么
var decoded =decodeURI(url);
You can try mystring = mystring.replace(/'/g,"");
您可以尝试
mystring = mystring.replace(/'/g,"");
to remove '
character from mystring. 从mystring中删除
'
字符。 you can try mystring = mystring.replace(/'/g,"/'");
您可以尝试
mystring = mystring.replace(/'/g,"/'");
to escape the single quotes of mystring with backslash /
. 使用反斜杠
/
来转义mystring的单引号。
But what I think is you should not make a url like this if there is really no strong(strange though) reason 但是我认为,如果确实没有任何强烈的(奇怪的)原因,则不应创建这样的网址
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.