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>