+;使用javascript传递值时缺少符号

+;使用javascript传递值时缺少符号,javascript,php,Javascript,Php,我尝试使用javaScript将两个值从一个页面传递到另一个页面,如下所示: window.location.href = "changefile.php?equation="+s+"&constant="+c; 在changefile.php中我得到的值如下 $eqn =$_GET['equation']; $cons=$_GET['constant']; 除以下情况外,它适用于所有情况: 假设方程的值为x+1 我使用window.location.href=“changefil

我尝试使用javaScript将两个值从一个页面传递到另一个页面,如下所示:

window.location.href = "changefile.php?equation="+s+"&constant="+c; 
changefile.php中
我得到的值如下

$eqn =$_GET['equation'];
$cons=$_GET['constant'];
除以下情况外,它适用于所有情况:

假设方程的值为x+1

我使用
window.location.href=“changefile.php?等式=“+s+”&constant=“+c

我得到的输出为x1。缺少+


请帮帮我。我做错了什么?

您需要使用

您应该使用对
s
c
参数进行编码

encodeURIComponent()
方法通过将某些字符的每个实例替换为表示字符UTF-8编码的一个、两个、三个或四个转义序列来编码统一资源标识符(URI)组件(对于由两个“代理”字符组成的字符,只有四个转义序列)

window.location.href = "changefile.php?equation=" + encodeURIComponent(s) + "&constant=" + encodeURIComponent(c);
window.location.href = "changefile.php?equation="+encodeURIComponent(s)+"&constant="+encodeURIComponent(c);