2017-05-04 90 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