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' 
      .$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 

图片转代码服务由CSDN问答提供 功能建议

我有一个多维数组,想把它作为参数发送给JS函数。 Google告诉我 json_encode()</ code>是可行的方法,但是当我尝试调用该函数时,我收到 unterminated string literal </ em>错误。</ p> \ n

这是我的代码:</ p>

  $ wynik_artefakty = $ polaczenie-&gt; query(“SELECT * FROM artefakty”);  
 $ tablica_artefakty = mysqli_fetch_all($ wynik_artefakty,MYSQLI_ASSOC); 
 $ tablica_artefakty = json_encode($ tablica_artefakty); 
 echo“&lt; div class ='wpis'
 onclick = \”dodajDiv('$ tablica_artefakty'  )\ “&gt;” 中 
。$ tablica_jednostek [$ i] ['nazwa']。“”。$ tablica_jednostek [$ i] ['koszt']。“&lt; / div&gt;”; 
 </ code> </ pre> 

json_encode()</ code>之后数组的示例回显:</ p>

  [{“Id”:“2”,“nazwa  “:”暴行的权杖“,”个人“:”
Gorgon“,”dla_maga“:”0“,”koszt“:”15“},{”Id“:”3“,”nazwa“:”Artefakt  dla 
 </ code> </ pre> 
 </ div>

1条回答 默认 最新

相关推荐 更多相似问题