This article mainly realizes the non-dynamic refresh query background data function, mainly uses the ajax+ashx+sqlserver to carry on the interaction.
You first need to reference jquery:
<language= "javascript" type= "Text/javascript" src =".. /js/jquery.js ">
HTML script:
<ID= "Tb_corpname" runat= "Server" MaxLength= " " Width=" 369px "></asp:textbox>
The foreground uses an event to invoke ASHX:
<script type= "Text/javascript" > $(function () { $("#tb_corpName"). Blur (function() {//Mouse loses focus event varCorpname = $ ("#tb_corpName"). Val (); $.ajax ({type:"Post",//How to submitURL: "/ashx/fzgpyshowdata.ashx",//path to the generic handlerData: {Corpname:corpname},//values passed in to the backgroundDataType: "JSON",//return value FormatSuccessfunction(data) {//return the thing that will be done after success, here is the return of a table$ ("#tb_CreditCode"). Val (data[0]. Creditcode); $("#tb_corpCode"). Val (data[0]. Corpcode); $("#tb_linkTel"). Val (data[0]. Linkphone); $("#corpProvince option[text= '" + data[0]. StateName + "']"). attr ("Selected",true); Showcity (); $("#corpCity option[text= '" + data[0]. Adminareaname + "']"). attr ("Selected",true); $("#tb_address"). Val (data[0]. Address); $("#tb_linkMan"). Val (data[0]. Linkman); $("#tb_Mobile"). Val (data[0]. Linkmobile); } }); }) })</script>
Backstage to receive the value sent by the foreground, to manipulate it:
Public voidProcessRequest (HttpContext context) {context. Response.ContentType="Text/plain"; stringCorpname = context. request["Corpname"]. Trim (). ToString (); //Receive the parameters sent by the front desk. if(Corpname! ="") { stringsql =@"Select top 1 corpname,creditcode,corpcode,linkphone,statename,adminareaname,linkman,linkmobile,address from Tbproductorder as a inner join tbstatedic as B on a.statenum = B.statenum INNER JOIN tbadminareaclass on a.citynum = Adminareaclassid where Corpname [email protected] ORDER by Corpname"; sqlparameter[] par=Newsqlparameter[1]; par[0] =NewSqlParameter ("@CorpName", Corpname); DataSet DS=dbherpler.load (SQL, par); stringJSON = Serializerhelper.tojsonstring (ds. tables[0]); //returns JSON-type data context. Response.Write (JSON); Context. Response.End (); } }
If more than one parameter is passed into the background, the data is separated by commas to write multiple parameters:
Data: {corpname:corpname, corpname2:corpname2}
. NET AJAX interaction with the background general handler (ASHX)