Copy link to clipboard
Copied
Hello,
I have seen similar topics but none seem to fit to my case. So I would like to fetch a JSON array from a web application in our local network once a button gets triggered by a user. Then the JS should write a value from that JSON array into a field on the PDF. Unfortunately it does not work. I have tested the code inside VSCode and it works fine there... What am I missing? Any help appreciated.
app.beginPriv();
fetch("http://domainXYZ/ajax/server_processing.php")
.then(response => response.json())
.then(data => {
const theData = data[0];
var dataConv = eval("(" + theData[0] + ")");
var FName = dataConv.Firstname;
});
this.getField('1').value = FName;
app.endPriv();
Copy link to clipboard
Copied
There is no "fetch" function in the Acrobat JavaScript model.
However, there is an "HTTP.Net" object that can be used to perform HTTP operations.
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#net-http
It cannot be used from a document script. The only internet access from within an untrusted document context is the form submit.
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#submitform
It's always helpful to look at the actual documentation.
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
Check the Javascript console for errors.
Copy link to clipboard
Copied
I'm not at all convinced you can use the Promise API in Acrobat. Have you just lifted this code from browser JavaScript? Adobe Acrobat Javascript Promises - Stack Overflow
Copy link to clipboard
Copied
There is no "fetch" function in the Acrobat JavaScript model.
However, there is an "HTTP.Net" object that can be used to perform HTTP operations.
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/JS_API_AcroJS.html#net-http
It cannot be used from a document script. The only internet access from within an untrusted document context is the form submit.
https://opensource.adobe.com/dc-acrobat-sdk-docs/library/jsapiref/doc.html#submitform
It's always helpful to look at the actual documentation.
Use the Acrobat JavaScript Reference early and often

