0

I try to parse my Json.

My Php:

<?php
  error_reporting(0);

  // LIBRARY
  require_once 'excel_reader2.php';

  // READ file example.xls
  $data=new Spreadsheet_Excel_Reader("leggimi.xls");
  $file_handle = fopen("leggimi2.csv", "r");

  while (!feof($file_handle) ) {
    $line_of_text = fgetcsv($file_handle, 1024);

    if ($line_of_text[0]=="SAT000000002574") {
      //print $line_of_text[0]." ".$line_of_text[1]." ".$line_of_text[2]." ".$line_of_text[3]." ".$line_of_text[4]." ".$line_of_text[5]." ".$line_of_text[6]." ".$line_of_text[7];

      $arr = array(
        'Nr SAT' => $line_of_text[0], 
        'Tipo Servizio' => $line_of_text[1], 
        'Stato' => $line_of_text[2], 
        'Attributo' => $line_of_text[3], 
        'Marca' => $line_of_text[4], 
        'Modello' => $line_of_text[5], 
        'Modello Guasto' => $line_of_text[6]
      );
      echo json_encode($arr);
    }
  }
  fclose($file_handle);
?>

My Function Js:

function example() { 
  alert("hello world");
  var response = "";
  var form_data = {
  };
  $.ajax({
    type: "POST", 
    url:  "http://sath3g.altervista.org/index.php", 
    data: form_data,
    success: function(response) {
      /*response = [{"Language":"jQuery","ID":"1"},
      {"Language":"PHP","ID":"3"},
      */

      var json_obj = $.parseJSON(response);//parse JSON
      var output="<ul>";

      for (var i in json_obj) {
        output+="<li>" + json_obj[i].Language + ",  " + json_obj[i].ID + "</li>";
      }
      output+="</ul>";
      $('span').html(output);
    },dataType: "json"//set to JSON    
  })    
}

But I have a problem. When run page Html there is a problem:"XMLHttpRequest cannot load http://sath3g.altervista.org/index.php. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access."

lighter
  • 2,808
  • 3
  • 40
  • 59
Loris812
  • 15
  • 3
  • https://developer.mozilla.org/en/docs/HTTP/Access_control_CORS – jgillich Apr 08 '14 at 10:23
  • You can't access cross domain request if **'Access-Control-Allow-Origin'** header is not present at the other end. – Jai Apr 08 '14 at 10:24
  • So?,What should I do? – Loris812 Apr 08 '14 at 10:36
  • possible duplicate of [No 'Access-Control-Allow-Origin' header is present on the requested resource.' Why is it not showing when I use POSTMAN?](http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource-w) – user2009750 Apr 08 '14 at 12:07

1 Answers1

0

Your request failed because you are visiting a different domain than your current page is on. It's a duplicate of "No 'Access-Control-Allow-Origin' header is present on the requested resource"

Community
  • 1
  • 1
xiaoboa
  • 1,953
  • 14
  • 18