-
Notifications
You must be signed in to change notification settings - Fork 1
Checklist to create new ajax request
-
Create a new route in Scripts/modules/routeInformation.ts export var routeName = new RouteInformation(name, url);
-
Create a new controller for the route Create a TypeScript file in routes/controllers/ function RouteName(req: express.Request, res: express.Response) { res.json(responseObject); res.end(); }; export = RouteName;
-
Add controller to controller list routes/controllers/index.ts import routeName = require("./RouteName"); var controllers = { ... routeName : routeName };
-
Define route routes/index.ts app.get(routeInfo.routeName.fullPath, ctrl.routeName);
Use request var ajax = require("ajax"); var routeInfo = require("routeInformation"); ... ajax.request( {endpoint: routeInfo.routeName.fullPath}, function(err, res){ if (err) { console.error(routeInfo.routeName.fullPath, status, err.toString()); return; } // use res object this.setState(res.body); }