We have not AMP'ified all our pages and are using javascript/ajax call to discover whether AMP page exists and then add the "amphtml" discoverability to tag accordingly.
- Make AJAX call to the webserver to see whether there is an equivalent AMP page.
- If yes, add to the head.
Loading up the website in Chrome shows the equivalent AMP page via AMP Validator extension.
However, https://search.google.com/test/amp?id=pNgSex6yfpSGiMsd8OVzeQ says it's not a valid AMP page. Is this because I am adding the "amphtml" via javascript?
Yes, you are modifying what is already an invalid AMP page and then serving it to the user with the modified html tag.
https://support.google.com/webmasters/answer/6340290