How to create a dynamic html form CSV

I am trying to create a form for displaying solar energy data in real time. Data can be obtained using the following jsp line.

http://pvoutput.org/service/r2/getstatistic.jsp?key=customer-key&sid=customer-id

Exiting this jsp is a comma delimited string similar to the one below:

5379600,49505,112075,0,216496,2.802,48,20100830,20151216,5.412,20151215

The first value is energy, the second is energy exported, and so on ... I need to break these values ​​down and display the HTML in a custom form.

I have reasonable knowledge of HTML, but very little javascript or any other knowledge of the programming language.

Any help would be greatly appreciated.

+4
source share
2 answers

You can get CSV using ajax like this (jQuery required):

$(document).ready(function() {

$.ajax({
  url: "http://pvoutput.org/service/r2/getstatistic.jsp?key=customer-key&sid=customer-id",
  cache: false
})
  .done(function(csv) {
    // comma separated values can be converted to an array using split
    var dataarray = csv.split(",")
    // populate your html with the single data elements
    $("#yourform first").html(dataarray[0])
    $("#yourform second").html(dataarray[1])
    // ...
  });
}

, HTML , AJAX, , HTML. document.ready ..

+1

php:

<?php
  $jsonurl = "http://pvoutput.org/service/r2/getstatistic.jsp?key=cust-key&sid=cust-id";

  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $jsonurl);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
  $result = curl_exec($ch);
  if( !$result ) {
   die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
  }
  curl_close($ch);
  $myArray = explode(',', $result);
?>

, :

<input type="text" id="energygen" value="<?php echo $myArray[0];?>">
0

Source: https://habr.com/ru/post/1620327/


All Articles