用ajax更新div,使用ajax更新div html和内容

  • Post author:
  • Post category:其他


您可以使用后面的代码中的jQuery和页面方法来实现此目的。

//Gets the list of requests

function getRequestList() {

// call server-side webmethod using jQuery

$.ajax({

type: “POST”,

contentType: “application/json; charset=utf-8”,

url: “Index.aspx/GetOrdersForApproving”,

data: “{ }”, // send an empty object for calls with no parameters

dataType: “json”,

success: displayRequests,

failure: reportError

});

}

//displays the requests in the ul

function displayRequests(result) {

// ASP.NET encapsulates JSON responses in a property “d”

if (result.hasOwnProperty(“d”)) { result = result.d; }

// iterate through player list and add info to the markup

var ul = $(“#requestsForApproval”);

for (i = 0; i < result.length; i++) {

var li = $(”

+ ”

” + result[i].OrderID + ” – ” + result[i].Supplier + ”

+ ”

+ ”

+ result[i].Description

+ ”

+ ”

+ ”

+ ”

+ ”

+ “Quant: ” + result[i].Quantity

+ ”

+ ”

+ “Price: ” + result[i].UnitPrice

+ ”

+ ”

+ “Total: ” + result[i].Value

+ ”

+ ”

+ ”

+ ”

+ ”

+ ”

  • Approve”

+ ”

Reject”

+ ”

+ “”

+ ”

“);

ul.append(li);

}

代码背后:

///

/// Gets a list of Request Lines

///

/// List of order lines

[WebMethod]

public static List GetOrdersForApproving()

{

try

{

List Lines = new List();

foreach (Objects.Database.OrderLine oOrderLine in Objects.Database.OrderLine.GetLinesWaitingFor(StaticStore.CurrentUser.UserID, int.MinValue))

{

Lines.Add(new iOrderLine(oOrderLine));

}

return Lines;

}

catch (Exception)

{

throw;

}