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> ");
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 (" ");
if ((Workitem.assigneeid! = null) &&
(Workitem.assigneeid! = Guid.Empty))
{
Sb. Append (Workitem.assigneedeptname);
}
Else
{
Sb. Append (Workitem.partdeptname);
}
Sb. Append (" ");
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