Last modified: 2008-02-07 01:58:57 UTC
Current api.php returns JSON as an anonymous object. This works great when accessing api.php via Ajax. It does not work for accessing api.php via the <script> tag. The reason for accessing api.php via the <script> tag is because it is not subject to the same-domain security policy. It would provide a way to access de.wiktionary.org from en.wiktionary.org. This is not possible with Ajax / XmlHttpRequest. Most people think of the <script> tag as a way to import executable JavaScript code, but it can just as well include data in the form of a variable declaration. Api.php in its current form is not usable for this since the JavaScript returned via JSON is not a valid JavaScript statement on its own: { "query": { "pages": { ... } } } } But it can be trivially transformed into an independent statement thus: var wgApiJsonResult = { "query": { "pages": { ... } } } }; Ideally an implementation would take as a parameter the variable name to assign to, but a standard variable name could easily be reused if this is nontrivial to achieve.
Isn't the typical way of doing this to specify a json callback function, which I believe is already supported?
Thanks Brion I think that's just what I need. The api.php documentation is so minimal it's easy to miss things.