Reputation: 11607
I have inherited a existing website with a large codebase. To handle ajax requests, the site has just one file called ajax.ashx
. Inside the file is a switch statement that looks like this:
switch (_json["m"])
{
case "editDetails":
if (requestIsValid(context))
_resp = AjaxMap.editDetailsPro(_json);
break;
case "addNewContact":
if (requestIsValid(context))
_resp = AjaxMap.addNewContact(_json);
break;
// ... and so on.
}
There is about 50 different cases.
For me, this is not the natural solution - I would probably have a different handler for each group similar requests.
I haven't worked with web technology much before. Is this the usual way to do it? And if so, what are the benefits?
Upvotes: 0
Views: 85
Reputation: 17498
It is perfectly OK.
You save page lifecycle overhead that usually occurs when using Ajax in its default WebForms facilities (UpdatePanel etc.) or even over proxies such as WCF / WebService.
Not to say that these infrastructures are useless, they are certainly not. But for the sole purpose of getting and request, do something and sending net data response - it's fine.
Upvotes: 1