Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/439.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
传递在javascript函数中包含空格的URL_Javascript_Php_Jquery - Fatal编程技术网

传递在javascript函数中包含空格的URL

传递在javascript函数中包含空格的URL,javascript,php,jquery,Javascript,Php,Jquery,我试图在javascriptonclick函数中传递URL,但它在控制台日志上返回missing)错误,我对它进行了实验,发现URL包含特殊字符,有时还包含空格,可以逃避onclick事件 我从PHP脚本获取url $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; 并在onclick事件中传递它 <a href="#" class="btn btn-primary" id="main" onclick="g

我试图在
javascript
onclick
函数中传递URL,但它在控制台日志上返回
missing)
错误,我对它进行了实验,发现URL包含特殊字符,有时还包含空格,可以逃避
onclick
事件

我从
PHP
脚本获取url

$actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
并在onclick事件中传递它

<a href="#" class="btn btn-primary" id="main" onclick="getContent(<?php echo $actual_link;?>);">Content 1</a>


我的问题是如何在javascript函数中传递url文本。

您需要在php输出周围加引号,以便将字符串传递给函数:

 onclick="getContent('<?php echo $actual_link;?>');">
                  // ^^                        ^^
onclick="getContent('<?php echo $actual_link;?>');">
onclick=“getContent(“”);”>
// ^^                        ^^

您需要在php输出周围加引号,以便将字符串传递给函数:

 onclick="getContent('<?php echo $actual_link;?>');">
                  // ^^                        ^^
onclick=“getContent(“”);”>
// ^^                        ^^
getContent
函数中缺少一个
'

onclick="getContent('<?php echo $actual_link;?>');">
onclick=“getContent(“”);”>
getContent
函数中缺少一个
'

onclick="getContent('<?php echo $actual_link;?>');">
onclick=“getContent(“”);”>