$.ajax () invokes the method in. cs to implement an AJAX operation example

Source: Internet
Author: User

First, CS code (returns a string that must be a static method and identifies WebMethod )

<summary>

Get History table

</summary>

<param name= "Preceptuid" ></param>

<returns></returns>

[system.web.services.webmethod]//1, this namespace is critical and must indicate

public static string Getcommentlist (String datalocator)//2, Static is essential

{

System.Text.StringBuilder sb = new System.Text.StringBuilder ();

Entityset<workitem> WorkItems;

if (string. IsNullOrEmpty (Datalocator))

{

return null;

}

Else

{

WorkItems = new Workflowbll (). Getcommentinout (Datalocator);

for (int i = 0; i < Workitems.count; i++)

{

Sb. Append ("<div>");

WorkItem WorkItem = workitems[i];

Process step Information

Sb. Append ("<font style= ' color: #f00; ' ><b> "+ Workitem.alias +" </b></font>&nbsp; ");

Handling people Information

Sb. Append ("" ");

if ((Workitem.assigneeid! = null) &&

(Workitem.assigneeid! = guid.empty) &&

(Workitem.partname! = workitem.assigneename))

{

Sb. Append (String. Format ("{0} ({1})", Workitem.assigneename, Workitem.partname));

}

Else

{

Sb. Append (Workitem.partname);

}

Sb. Append ("&nbsp;");

if ((Workitem.assigneeid! = null) &&

(Workitem.assigneeid! = Guid.Empty))

{

Sb. Append (Workitem.assigneedeptname);

}

Else

{

Sb. Append (Workitem.partdeptname);

}

Sb. Append ("&nbsp;");

if ((Workitem.assigneeid! = null) &&

(Workitem.assigneeid! = Guid.Empty))

{

Sb. Append (Workitem.assigneerank);

}

Else

{

Sb. Append (Workitem.partrank);

}

Sb. Append ("<br/>");

Time Information

if (workitem.finishtime! = NULL && WorkItem.FinishTime.Value! = DateTime.Parse ("2100-12-31 23:59:59"))

{

Sb. Append (workItem.FinishTime.Value.ToString ("yyyy mm DD Day hh:mm"));

}

else if (workitem.readtime! = null)

{

Sb. Append (workItem.ReadTime.Value.ToString ("yyyy mm DD Day hh:mm"));

}

Else

{

Sb. Append (workItem.ReceTime.Value.ToString ("yyyy mm DD Day hh:mm"));

}

Sb. Append ("<br/>");

Handling Opinions

Sb. Append (workitem.partcomment);

Sb. Append ("<br/>");

Sb. Append ("<br/>");

Sb. Append ("</div>");

}

}

Sb. Append ("<a name= ' #anchorTO ' ></a>");

Return SB. ToString ();

}

Second, HTML Code (note the format, use RESULT.D gets the value returned by the method)

$.ajax ({

Type: ' POST ',

async:false,// If this property is not set, the requested data will probably not be up-to-date but the last requested data

ContentType: ' Application/json ',

URL: ' Todolist.aspx/getcommentlist ',

DataType: ' json ',// This code format is basically fixed

Data: ' {' datalocator ': ' + data_locator + ' '} ',// 1, note the format of the parameter passed in (quotation marks)

Error:function (Err) {

$menuDiv. HTML (' Error, error message: ' + err + ', please try again! ');

},

Success:function (Result) {

$menuDiv. HTML (RESULT.D);//2, using result.d to get The data returned by the CS method

window.location = "#anchorTO";

}

});

$.ajax () invokes the method in. cs to implement an AJAX operation example

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.