Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.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/0/email/3.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 json_编码转义特殊字符_Javascript_Php_Jquery_Arrays - Fatal编程技术网

Javascript json_编码转义特殊字符

Javascript json_编码转义特殊字符,javascript,php,jquery,arrays,Javascript,Php,Jquery,Arrays,我想将php数组传递给jQuery函数。 我尝试将数组作为json\u encode发送,如下所示: <button onclick='callFunction(<? echo json_encode($myArray); ?>)'></button> 一切都很好 但是如果我有这样一个数组(带有“) 我的功能不再工作-我的控制台将显示: SyntaxError:意外的EOF 如何解决此问题?尝试使用 我建议您处理任何进入html的内容的方法是: <bu

我想将
php
数组传递给
jQuery
函数。
我尝试将数组作为
json\u encode
发送,如下所示:

<button onclick='callFunction(<? echo json_encode($myArray); ?>)'></button>
一切都很好

但是如果我有这样一个数组(带有

我的功能不再工作-我的控制台将显示:

SyntaxError:意外的EOF

如何解决此问题?

尝试使用


我建议您处理任何进入html的内容的方法是:

<button onclick='callFunction(<? echo htmlentities(json_encode($myArray),ENT_QUOTES); ?>)'></button>

我试了一下,检查了回声。在这个过程之后,回显为“null”是正确的吗?问题仍然是一样的:SyntaxError:意外的EOFForgot标志,再试一次这看起来好多了!!非常感谢:)
{"Date":"2018-01-26 12:55:00","Details":"FORLI' IT"}
<button onclick='callFunction(<? echo json_encode(addslashes($myArray)); ?>)'></button>
<button onclick='callFunction(<? echo htmlentities(json_encode($myArray),ENT_QUOTES); ?>)'></button>