title: JSONP using ContentService of Google Apps Script?
body: <p>I'm trying to use <a href="https://developers.google.com/apps-script/content_service" rel="nofollow noreferrer">ContentService</a>, to serve <a href="http://en.wikipedia.org/wiki/JSONP" rel="nofollow noreferrer">JSONP</a> in a webpage with <a href="https://developers.google.com/apps-script/" rel="nofollow noreferrer">Google Apps Script</a>, following the samples provided in <a href="https://developers.google.com/apps-script/content_service" rel="nofollow noreferrer">this link</a> under <em>"Serving JSONP in Web Pages"</em> sub-topic.<br>
  <br>GS code: </p>
  
  <pre><code>function doGet(request) {
    var events = CalendarApp.getEvents(
      new Date(Number(request.parameters.start) * 1000),
      new Date(Number(request.parameters.end) * 1000));
    var result = {
      available: events.length == 0
    };
    return ContentService.createTextOutput(
      request.parameters.prefix + '(' + JSON.stringify(result) + ')')
      .setMimeType(ContentService.MimeType.JSON);
  }
  </code></pre>
  
  <p>HTML/JS Code:</p>
  
  <pre><code>&lt;script src="https://script.google.com/macros/s/AKfycbwZCY0qrZ09szGvKOttA30IaJkdMAZrh_oNnvv0qzCqFWyuO5Wc/exec?start=1325437200&amp;end=1325439000&amp;prefix=alert"&gt;&lt;/script&gt;
  </code></pre>
  
  <p><br/>I published it, by deploying the GS code as <code>webapp</code>, with the following parameters: </p>
  
  <ul>
  <li>Executing the app as: User accessing the web app</li>
  <li>Who has access to the app: Anyone</li>
  </ul>
  
  <p>Unfortunately, whenever I try to run/open the HTML file containing the code, I got the following error in browser's console, and nothing happens:</p>
  
  <p><img src="https://i.stack.imgur.com/n5gQm.png" alt="enter image description here"></p>
  
  <p><strong><em>How to run this sample provided in Google Apps Script link without errors ?</em></strong></p>
  
  <p><hr><br><br>
  <strong>[OPTIONAL] Investigating the issue in details:</strong><br/><br/>
  The error found in resources files generate by the browser is as follows:
  <img src="https://i.stack.imgur.com/iisqV.png" alt="enter image description here"></p>
  
  <p>And the browser translated DOM is as follows:</p>
  
  <pre><code>&lt;html&gt;
     &lt;head&gt;
         &lt;script src="https://script.google.com/macros/s/AKfycbwZCY0qrZ09szGvKOttA30IaJkdMAZrh_oNnvv0qzCqFWyuO5Wc/exec?start=1325437200&amp;amp;end=1325439000&amp;amp;prefix=alert"&gt;
         &lt;/script&gt;
     &lt;/head&gt;
     &lt;body&gt;&lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The generated link, in my case is:<br>"<a href="https://script.google.com/macros/s/AKfycbwZCY0qrZ09szGvKOttA30IaJkdMAZrh_oNnvv0qzCqFWyuO5Wc/exec?start=1325437200&amp;end=1325439000&amp;prefix=alert" rel="nofollow noreferrer">https://script.google.com/macros/s/AKfycbwZCY0qrZ09szGvKOttA30IaJkdMAZrh_oNnvv0qzCqFWyuO5Wc/exec?start=1325437200&amp;end=1325439000&amp;prefix=alert</a>" 
  <br><br> If this link is placed in browser address bar, it shows the following message:
  <img src="https://i.stack.imgur.com/ddTBr.png" alt="enter image description here"></p>
  
  <p>which means that the returned authorization response wasn't able to be displayed on browser and being translated as valid DOM.</p>
  
  <p><strong><em>How to overcome this issue ?</em></strong></p>