Background code
/// <Summary>
/// Summary of commonhandler
/// </Summary>
Public class commonhandler: ihttphandler
{
Public void processrequest (httpcontext context)
{
Context. response. expires =-1;
Context. response. contenttype = "text/plain ";
If (string. Equals (context. request ["ajaxmethod"]? ""), "Getroom", stringcomparison. ordinalignorecase ))
{
Roomselect (context );
}
Context. response. End ();
}
Public void roomselect (httpcontext context)
{
Httprequest request = context. request;
Httpresponse response = context. response;
String val = (request ["Val"]? ""). Trim ();
VaR list = businessroom_dal.businessroomlist.where (P => P. roomregion = Val );
Stringbuilder jsonbuilder = new stringbuilder ("{\" ID \ ": \" \ ", \" Val \ ": \" all \"},");
Foreach (businessroom model in List)
{
Jsonbuilder. appendformat ("{\" ID \ ": \" {0} \ ", \" Val \ ": \" {1} \ "}},", model. ID, model. room. replace ("\"",""));
}
String JSON = "[" + jsonbuilder. tostring (). trimend (',') + "]";
Response. Write (JSON );
}
Public bool isreusable
{
Get
{
Return false;
}
}
}
Front-end:
Function changeselect (OBJ, ddlroomid ){
OBJ = $ (OBJ );
Var val = obj. Val ();
OBJ. Next ('img '). Show ();
If (Val! = ""){
$. Ajax ({
Type: "Get ",
URL: '<% = resolveurl ("~ /Ashx/commonhandler. ashx ") %> ',
Data: 'ajaxmethod = getroom & val = '+ escape (VAL ),
Datatype: "JSON ",
Success: function (data ){
If (Data! = NULL ){
// Eval ("(" + RET + ")")
Alert (data [0]. DemoData );
}
OBJ. Next ('img '). Hide ();
},
Complete: function (){
OBJ. Next ('img '). Hide ();
},
Error: function (XMLHttpRequest, textstatus, errorthrown ){
// Usually in textstatus and errorthrown
// Only one containing information
// The options parameter passed when calling this Ajax request
}
});
}
}