Skip to content

Instantly share code, notes, and snippets.

@coilysiren
Last active February 22, 2018 20:18
Show Gist options
  • Save coilysiren/d29578c8bec4623580ab89ff1f1b7189 to your computer and use it in GitHub Desktop.
Save coilysiren/d29578c8bec4623580ab89ff1f1b7189 to your computer and use it in GitHub Desktop.
using jquery ajax methods on both the client side and the server side
import * as jsdom from "jsdom";
import * as jqueryClientSide from "jquery";
class ClientSideService {
public get jquery(): jqueryClientSide { return jqueryClientSide; }
public doGetRequest() { return this.jquery.get("/route") }
public doPostRequest() { return this.jquery.post("/route") }
}
class ServerSideService extends ClientSideService {
public get jquery(): jqueryClientSide {
const { JSDOM } = jsdom;
const dom = new JSDOM(`<!DOCTYPE html></html>`);
const jqueryServerSide = require("jquery")(dom.window);
return jqueryServerSide;
}
}
{
"engines": {
"node": "9.5.0",
"npm": "5.6.0"
},
"dependencies": {
"typescript": "<2.7",
"jquery": "^3.3.1",
},
"devDependencies": {
"jsdom": "^11.6.2",
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment