The idea here is to make the **minimum viable** AJAX backend. Rather than via the URI, the page is requested via a JSON message. So we need to take JSON via POST, and decode it, find the file # Backend ```php $path, "source" => $source, "input" => $data, "json" => $json ]; $ptmd = new Parsedown(); $pinput = preg_replace('/\[\[([^\]]+)\]\]/','[\1](\1)',$source); $reply["pinput"] = $pinput; $html = $ptmd->text($pinput); $reply["html"] = $html; $reply["nhtml"] = ""; send_as_json($reply); ``` # Frontend ## app.js ```js class Ajax { constructor(backend) { this.backend = backend } getPage(path,callback) { const request = { path } return this.dispatch(request,callback) } putPage(path,source,callback) { const request = { "type": "put", path, source } return this.dispatch(request,callback) } dispatch(request,callback) { console.log(request) $.ajax({ type: "POST", data: JSON.stringify(request), url: this.backend, success: callback, dataType: "json" }).fail(error => { const { responseText } = error console.log({responseText,error}) const errorData = { pagename: "ERROR", navbar: `Failed to load page ${url}`, tags: [], body: responseText.replace(/&/g,"&").replace(/>/g,">").replace(/ window.q = (x,y=document) => y.querySelector(x) window.qq = (x,y=document) => Array.from(y.querySelectorAll(x)) ```