2017-05-04 50 views
-1

我正致力于将数据发送到ajax。如何在php中退出javascript代码

 $phpArray = array("ok", " 
      <script> 
     mygallery = [ 
         {type: "image", image: "img/gallery/slider/1.jpg", thmb: "img/gallery/slider/thumbs/1.jpg", alt: "", title: "", description: "", titleColor: "#000000", descriptionColor: "#000000"}, 
     {type: "image", image: "img/gallery/slider/2.jpg", thmb: "img/gallery/slider/thumbs/2.jpg", alt: "", title: "", description: "", titleColor: "#000000", descriptionColor: "#000000"}, 
</script>" 
     ); 
    echo json_encode($phpArray); 

如何正确执行此操作?我曾尝试在网上的javascript逃走,但doesn't工作

+0

而且问题是 –

+0

问题是我无法得到它的工作,因为我有(”“) – MANGA

+0

刚刚在本地运行,并按照我的预期工作 –

回答

0

就难逃“用反斜杠:

$phpArray = array("ok", " 
      <script> 
     mygallery = [ 
         {type: \"image\", image: \"img/gallery/slider/1.jpg\", thmb: \"img/gallery/slider/thumbs/1.jpg\", alt: \"\", title: \"\", description: \"\", titleColor: \"#000000\", descriptionColor: \"#000000\"}, 
     {type: \"image\", image: \"img/gallery/slider/2.jpg\", thmb: \"img/gallery/slider/thumbs/2.jpg\", alt: \"\", title: \"\", description: \"\", titleColor: \"#000000\", descriptionColor: \"#000000\"}, 
</script>" 
); 
echo json_encode($phpArray); 
+0

谢谢你的回复。但我在JavaScript中使用的脚本只接受双引号 – MANGA

+0

,所以现在它可以工作? – Lycidias

+0

它实际上工作!但我认为,因为我发送里面的数据,这是为什么? – MANGA