I am wondering, i fix older web applications these days and i often stumble upon the same problem where i can't find a solution for it.
Javascript applications often get their data from other sources. In my case it's php. Those Javascript applications expect data given to them in a certain way and if they don't get the data in that specific way, an error occurs and the application breaks.
This can be hard to debug because if someone decided to edit the php function for example that delivers that data, they usually won't get any hints from their modern IDE that the data may be returned in an incorrect manner.
Is there a way you could make an interface between php and javascript for example so that they both need to comply to it? Just like a php interface.
I also know that when you use typescript for example you could create an interface for the javascript application. And then you could create the same kind of interface for php.
As others have hinted, what you are looking for here is a schema, which specifies the format of your inputs and outputs; and a wider contract, which specifies the actions, in the form of URLs, method names, etc.
For XML, the schema would most likely be specified using XML Schema or RelaxNG; for JSON, there is JSON Schema and probably others.
The wider contract will vary a lot depending on the style of your API. WSDL files are commonly used to define a SOAP API (which is just a particular convention for XML-over-HTTP), tools like Swagger and OpenAPI can specify a REST-style API, usually using JSON.
All of these can then be fed into tools which automatically generate tests that your implementation meets its contract, as well as documentation, etc. These tests and documentation are actually your aim: for a legacy website with a bunch of AJAX calls that don't form a coherent API, the best place to start might be a series of unit tests that can confirm the same input gives the same output after you make a change.
The only thing that comes to mind is SOAP, where the WSDL Document gives information on the SOAP function (incl. parameters and datatypes) and its response. It is well-known and since it is in XML, it is language independent.
I don't know how the IDE support is, but the standard has been around for some time (at least since 2001) so I think there should be some plugins available that can make your life easier.
If you have control of the server, maybe you can run the PHP application on Node, so your Javascript/Typescript application can directly communicate with the Node server and make use of the Typescript type definitions. But I'm guessing that is not an option :)