title: Access to XMLHttpRequest at 'https://script.google.com/macros/ - has been blocked by CORS policy
body: <p>I have a Spreadsheet, I created script.google.com code as web API to export spread sheet data as json but when write code to read json has problem &quot;has been blocked by CORS policy</p>
  <pre><code>var dataJSON;
      
  
      function viewVillages(){
            
          var xmlhttp = new XMLHttpRequest();
           
  var url = &quot;script.google.com&quot;;
          xmlhttp.onreadystatechange = function() {
              if (this.readyState == 1  ) {
                  console.log(&quot;1&quot;);
                  
              }
              if (this.readyState == 2  ) {
                  console.log(&quot;2&quot;);
                  
              }
              if (this.readyState == 3  ) {
                  console.log(&quot;3&quot;);
                  
              }
              if (this.readyState == 4 &amp;&amp; this.status == 200) {
                  console.log(&quot;4&quot;);
                  
                  var myArr = JSON.parse(this.responseText);
                  myFunction(myArr);
                  
              }
          };
           
          xmlhttp.open(&quot;GET&quot;, url, true);
          xmlhttp.send();
          
          function myFunction(arr) {
              dataJSON=arr;
          }
          
      }
  </code></pre>
  <p>code for publish web app API
  i publish this as web app API , by anyone can access this app,
  this link for result</p>
  <p><a href="https://script.googleusercontent.com/macros/echo?user_content_key=idpffu-SYlDxC7EuWBf-NqgCGhMPNeiXeBQUt-Tk-dDFoqb6JYzKvNyw405zrlyQEDgaTlGUksHOTbbV5Aj9STHlRS9FtMxjm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_1xSncGQajx_ryfhECjZEnNhRObYMMbRvDsIN0NCwYbNGFGtS5GcRpQ0e15R5Rfx0Jy77eUQpR9E0M2qu45i7T6drUwBK3ZY_&amp;lib=MMMohOFXoOCvrcVJ1jiPfgJKNXc8Lw_h0" rel="nofollow noreferrer">https://script.googleusercontent.com/macros/echo?user_content_key=idpffu-SYlDxC7EuWBf-NqgCGhMPNeiXeBQUt-Tk-dDFoqb6JYzKvNyw405zrlyQEDgaTlGUksHOTbbV5Aj9STHlRS9FtMxjm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_1xSncGQajx_ryfhECjZEnNhRObYMMbRvDsIN0NCwYbNGFGtS5GcRpQ0e15R5Rfx0Jy77eUQpR9E0M2qu45i7T6drUwBK3ZY_&amp;lib=MMMohOFXoOCvrcVJ1jiPfgJKNXc8Lw_h0</a></p>
  <pre><code>function doGet(e){
   var ss = SpreadsheetApp.openByUrl(&quot;url&quot;);
   var sheetgoogle = ss.getSheetByName(&quot;labs&quot;); 
   return getUsers(sheetgoogle); 
  }
  
  function getUsers(sheetgoogle){
    var ps = {};
    var dataArrayGoogle = [];
  var rowsGoogle = sheet.getRange(2,1,sheetgoogle.getLastRow()-1, sheetgoogle.getLastColumn()).getValues();
    for(var i = 0, l= rowsGoogle.length; i&lt;l ; i++){
      var dataRowGoogle = rowsGoogle[i];
      var recordSheet={} ;
      recordSheet[0] = dataRowGoogle[0];
      recordSheet[1] = dataRowGoogle[1];
      dataArrayGoole.push(recordSheet);
    }  
    ps.user = dataArrayGoogle;
    var result = JSON.stringify(ps);
    return ContentService.createTextOutput(result).setMimeType(ContentService.MimeType.JSON)
    
  } 
  </code></pre>