1

here is My code.when I activate below code via wordpress custom plugin,It shows 'var' (T_VAR), error . error:- Parse error: syntax error, unexpected 'var' (T_VAR),expecting end of file in /var/www/wptbox/wp-content/plugins/...... on line ,var data = "";

help me to resolve it. I found this similar answer (PHP parse/syntax errors; and how to solve them I can't get real answer.

var data = "";
$(document).ready(function() {
  getHealthData();
});
/**
 *Gets data from API
 **/
function getHealthData() {
  $.ajax({
    type: "GET",
    dataType: "json",
    url: "https://www.hpb.health.gov.lk/api/get-current-statistical",
    data: {
      action: "get_data"
    },
    success: function(response) {
      //getting value from server
      var value = response.data;

      data = "<h5>local_total_cases :</h5><b>" + value['local_total_cases'] + "</b><br/><h5>local_deaths :</h5><b> " + value['local_deaths'] + "</b><br/><h5> local_new_deaths : </h5><b>" + value['local_new_deaths'] + "</b><br/><h5>local_recovered : </h5> <b>" + value['local_recovered'] + "</b><br/><h5>local_new_cases :</h5> <b>" + value['local_new_cases']+"</b>";
      //putting values in div with id="data"
      $("#data").html(data);
      //adding value separately 
      $("#something").text("local_total_cases :" + value['local_total_cases'])

      }
  });
}
Mr.Oneday
  • 37
  • 7
  • 1
    the PHP code is responsible for the issue not the ajax call, you need to put the PHP code here. – Kamyar Mirzavaziri Mar 26 '20 at 06:33
  • @KamyarMirzavaziri I have html code and above code only.
    Those are working in Jfiddle correctly (https://jsfiddle.net/tx2m4fyn/) but another checkers says (https://phpcodechecker.com/ https://jsonlint.com/) above error,my wordpress site also says..
    – Mr.Oneday Mar 26 '20 at 06:50
  • @KamyarMirzavaziri error occurs on ,var data = ""; – Mr.Oneday Mar 26 '20 at 07:02
  • 1
    _“when I activate below code via wordpress custom plugin”_ - what custom plugin? Do you mean something that can execute arbitrary PHP code? Then it probably expects PHP code _without_ ` { your JS / HTML code here } – CBroe Mar 26 '20 at 08:34

0 Answers0