Answer the question
In order to leave comments, you need to log in
How to get a response from a script called via POST / GET in the form of return?
I would like to pull the POST / GET script with a request and receive a response in the form of only a specific value, but I tried different return options and they return Html, is there a way to return the value like through a php file call?
Answer the question
In order to leave comments, you need to log in
Perhaps you want to deploy your script as an api service?
If this is the case, then do the following:
1. Menu Publish > Deploy as a web application, in the settings, select on my behalf and for everyone, including anonymous users.
2. In the doPost or doGet function, return the ContentService, depending on what result you expect, such a result format and specify, for example, like this:
function doGet(e) {
const result = {};
// ваш код
if ( e.parameter.callback ) {
return ContentService
.createTextOutput(`${ e.parameter.callback }(${ JSON.stringify(result) })`)
.setMimeType(ContentService.MimeType.JAVASCRIPT);
} else {
return ContentService
.createTextOutput(JSON.stringify(result))
.setMimeType(ContentService.MimeType.JSON);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question