0

I'm not even importing any files. All I want to do is transpose a HTML table (id = "valuation_table").

Here's the script I've used

<script>
   $("#valuation_table").each(function() {
       var $this = $(this);
       var newrows = [];
       $this.find("tr").each(function(){
         var i = 0;
         $(this).find("td, th").each(function(){
         i++;
         if(newrows[i] === undefined) { newrows[i] = $("<tr></tr>"); }
         if(i == 1)
           newrows[i].append("<th>" + this.innerHTML  + "</th>");
         else
           newrows[i].append("<td>" + this.innerHTML  + "</td>");
        });
      });
      $this.find("tr").remove();
      $.each(newrows, function(){
      $this.append(this);
    });
  });
 </script>

It works when I used this during the debugging phase. When I add it to the main project, it gives me the cross-origin frame error. All of my files are from the same source. I am not calling it from any link. My code so far reads an excel file from the disk, stores it to a database table, displays it, the js script is called here. I'm not calling an iframe.

The html file

<head>
    <title>test</title>
    <!-- Latest compiled and minified CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">

    <!-- jQuery library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

    <!-- Latest compiled JavaScript -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
    <?php include_once 'tableSWAG.php'; ?>

    <script>

      $("#valuation_table").each(function() {
            var $this = $(this);
            var newrows = [];
            $this.find("tr").each(function(){
                var i = 0;
                $(this).find("td, th").each(function(){
                    i++;
                    if(newrows[i] === undefined) { newrows[i] = $("<tr></tr>"); }
                    if(i == 1)
                        newrows[i].append("<th>" + this.innerHTML  + "</th>");
                    else
                        newrows[i].append("<td>" + this.innerHTML  + "</td>");
                });
            });
            $this.find("tr").remove();
            $.each(newrows, function(){
                $this.append(this);
            });
        }); 
    </script>

</body>

tableSwag.php

<?php
  include_once 'swegAgain.php';
  include_once 'db.php';

  $sql = "select * from $table_name";
  $result = $con->query($sql);

  $nr = mysqli_num_rows($result);
  $nc = mysqli_num_fields($result);
  $recNew = array();

  echo '<div id="peer_table">';
  echo '<table id = "valuation_table" class="table table-bordered table-stripped table-condensed">' . "\n";
  echo '<tr>
          <th> </th>
          <th>Sweg</th>
          <th>Sweg1</th>
          <th>Sweg2</th>
  </tr>';
  for($i = 1;$i <= $nr; $i++) {
      echo '<tr>';
      $records = mysqli_fetch_array($result);
      for($j = 0; $j < $nc; $j++){
          echo '<td>' . $records[$j] . '</td>';
      }
      echo "</tr>";
  }
  echo '</table>';
  echo '</div>';
?>

This code works finally individually. When I integrate it the project that I'm working on, I get the cross-origin frame error. Any help would be appreciated.

Console Log SQL Records

  • Possible duplicate of [SecurityError: Blocked a frame with origin from accessing a cross-origin frame](http://stackoverflow.com/questions/25098021/securityerror-blocked-a-frame-with-origin-from-accessing-a-cross-origin-frame) – Muhammad Saqlain Jan 20 '17 at 10:05
  • There is nothing cross-origin going on in this code, so I am assuming this error is not related to _this_ code specifically, but other code in your main project. – somethinghere Jan 20 '17 at 10:45
  • @somethinghere I checked. My phplogs show nothing. I'm new to web development, I've tried everything else. :/ –  Jan 20 '17 at 10:48
  • Why look in phplogs? This is clearly related to Javascript. The error thrown in your console should also give you an indication of on what line that error occurred, and then you can follow the stack trace down to find out which of your own and/or built-in functions triggered it. Keep looking until you find the offending line! – somethinghere Jan 20 '17 at 10:51
  • It must be to do with whatever is in your `$records` sql result - something in there contains HTML that is causing this after it's being added to the page. – James Thorpe Jan 20 '17 at 11:05
  • @JamesThorpe the `$records` actually doesn't contain any html. I'm echoing html table from the file. It works in the test environment. Doesn't with the main project. I tried echoing the script with the same file, doesn't work. –  Jan 20 '17 at 11:18
  • Can you add an example of some records that are triggering this behaviour to your question? It must be something in there that's doing it, based on what you're saying. – James Thorpe Jan 20 '17 at 11:19
  • @JamesThorpe, edited the question. It has a picture of the `$records` that i'm retrieving –  Jan 20 '17 at 11:21
  • Are you sure that there's not some hidden html in the table you've got a screen shot of? You need to inspect the raw data. – James Thorpe Jan 20 '17 at 11:25
  • @JamesThorpe, I'm sure that there is no hidden html in the table –  Jan 20 '17 at 11:34

0 Answers0