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 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 使用Java milo连接Kepserver服务端报错?
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了