dqlk31541 2018-01-19 16:14
浏览 55
已采纳

将PHP数组发送到在echoed string中调用的JS函数

I have a multidimensional array and want to send it as a parameter to JS function. Google told me that json_encode() is the way to go, but I get an unterminated string literal error when I try to call the function.

Here's my code:

$wynik_artefakty = $polaczenie->query("SELECT * FROM artefakty"); 
$tablica_artefakty = mysqli_fetch_all($wynik_artefakty,MYSQLI_ASSOC);
$tablica_artefakty = json_encode($tablica_artefakty);

 echo "<div class='wpis' 
       onclick=\"dodajDiv('$tablica_artefakty')\">" 
      .$tablica_jednostek[$i]['nazwa']." ".$tablica_jednostek[$i]['koszt']."</div>";

And the example echo of the array after json_encode():

[{"Id":"2","nazwa":"Sceptre of Atrocities","personal":"The 
Gorgon","dla_maga":"0","koszt":"15"},{"Id":"3","nazwa":"Artefakt dla 
maga","personal":"","dla_maga":"1","koszt":"10"}] 
  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 关于selenium网页闪退
      • ¥15 怎么用PYTHON解类似于x = y+zx + cy = x+zy + v的方程
      • ¥300 FLASH AS2.0制作一个类似手机上下滑动一样的效果
      • ¥15 为什么使用openFoam 中的icoFoam计算圆柱扰流时出现浮点数例外(核心已转储)
      • ¥15 51单片机外部中断控制数码管
      • ¥15 创建网页里面的图片显示不出来
      • ¥15 语音控制的编写?(语言-c#)
      • ¥15 matlab输入书上的代码运行错误
      • ¥15 matlab怎么做三维曲面
      • ¥50 sph光滑粒子法能否解决阶跃性的问题