Jquery Ajax asynchronously acquires data

Source: Internet
Author: User

Because it is part of the project, I am only part of it.CodeFor details, refer:

<Table width = "  100%  " Border = "  0  " Cellspacing = "  0  " Cellpadding = "  5  " > <Tr> <TD id = " Latestnews  " Height = "  330  " Align = "  Center  " Valign = "  Top  "   Class = "  Font14  " Style = " Border: #7baed9 solid 1px; Border-top: none; padding: 10px; "  > </TD> </tr> </table>

It is mainly used to obtain data through jquery Ajax and display it in the ID number "latestnews" TD. The following is the Ajax code:

<SCRIPT type = "  Text/JavaScript  " > $ (Function () {$. Ajax ({type:  "  Post  " , URL:  "  Ceo2012/latestnews. ashx  "  , Contenttype:  "  APP/JSON; charset = UTF-8  "  , Datatype:  "  JSON  "  , Success: function (data) {$ (  "  # Latestnews "  ).Html (data) ;}, error: function (error) {$ (  "  # Latestnews  " Pai.html ( "  No information has been published!  "  );}});}); </SCRIPT>

Below is a general method for processing latestnews. ashx in the ceo2012 Folder:

 ///   <Summary>          ///  Latest media reports ///   </Summary>          ///   <Param name = "context"> </param>          Public   Void  Processrequest (httpcontext context) {context. response. contenttype = "  Text/plain  "  ; JavascriptserializerJavascriptSerializer = New Javascriptserializer (); string strhtml = "  <Ul style = 'text-align: left'>  "  ; Datatable dt = New  Datatable (); newsrule = New  Newsrule (); dt = Newsrule. getnewsbytid ( 640 , 15 , "  Sortid DESC "  );  If (Dt. Rows. Count = 0  ) {Context. response. Write (  "  No information has been published!  "  );  Return  ;}  For ( Int I = 0 ; I <DT. Rows. Count; I ++){  If (! String. isnullorempty (Dt. Rows [I] [ "  Aurl  "  ]. Tostring () {strhtml + = "  <Li> <a href ='  " + Dt. Rows [I] [ "  Aurl  " ]. Tostring () + "  'Title =' " + Dt. Rows [I] [ "  Title  " ]. Tostring () + "  'Target = \ "_ blank \">  " + Dt. Rows [I] [ "  Title  " ]. Tostring () + "  </A>  "  ;}  Else {Strhtml + = "  <Li> <a href = \ "http://www.sino-manager.com/  " + Returndate (datetime. parse (Dt. Rows [I] [ "  Pubtime  " ]. Tostring (). tow.datestring () + "  _  " + Dt. Rows [I] [ "  Postid  " ]. Tostring () +"  . Html \ "Title = \"  " + Dt. Rows [I] [ "  Title  " ]. Tostring () + "  \ "Target = \" _ blank \ ">  " + Dt. Rows [I] [ "  Title  " ]. Tostring () + "  </A> </LI>  " ;} Strhtml + = "  </Ul>  "  ; String content = Javascriptserializer. serialize (strhtml); context. response. Write (content ); 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.