du521521521 2016-08-20 15:25
浏览 21
已采纳

试图在javascript中的php中添加新行

Im still trying to get used to javascript and php so hopefully it isn't a noob mistake. Ok So after looking around other posts posted here I still can't find how to make a new line. What I mean by this is the following,

1°/ enter image description here 2°/ enter image description here 3°/ enter image description here 4°/ enter image description here

*just as a quick side note in the above images you can see three red boxes and inside the 3 red boxes is in this case the Callsign Of the person and The Aircraft they are flying. The data is being pulled from a XML file with no issue.

But what I am struggling with is Having 1 Callsign And 1 Aircraft Per line.

        var board = new DepartureBoard (document.getElementById ('test'), { rowCount: 10, letterCount: 40 }); 
        board.setValue (['<?php 
            $EGLL = simplexml_load_file('EGLL.xml');
            foreach($EGLL as $info) {
                echo $info->callsign . " "  .  $info->aircraft . " " ;
            }
            ?>'])

    </script>
    <?php
    file_put_contents("EGLL.xml",         fopen("http://api.vateud.net/online/departures/EGLL.xml", 'r'));
    ?>
    <script src="http://code.jquery.com/jquery-latest.js"
    type="text/javascript"></script>

So That is the code that I am using to get the data Onto the Board but when I add a for example or echo nl2br it just returns back with a blank webpage. Picture 2 Shows What I See and also in that picture I show where exactly I put the and i also tried it with the echo nl2br I get the exactly same white screen. Aswell in that picture It shows All the Callsign's And Aircraft's in a vertical List unlike when I remove the its all horizontal like picture 4 Hopefully the 4 Pictures in the 1 link didn't confuse but I need 10 Rep points in order to post 2 or more :/ But hopefully you understand what I am trying to do. Thanks - Ciaran

  • 写回答

1条回答 默认 最新

  • dongshan6870 2016-08-20 17:16
    关注

    You should send the values to form a javascript array. Watch for the ' location (one per item):

    <?php
      $EGLL = simplexml_load_file('EGLL.xml');
    ?>
    
    <script>
      var board = new DepartureBoard (document.getElementById ('test'), { rowCount: 10, letterCount: 40 }); 
      board.setValue ([
        <?php 
          foreach($EGLL as $info) {
            echo "'" . $info->callsign . " "  .  $info->aircraft . "'," ;
          }
        ?>
      ]);
    </script>
    

    This should generate the javascript code as follows, which you can corroborate by viewing your webpage sourcecode:

    board.setValue(['AAL7422 B752','AIC234 B738L']);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!