2.1.3 多个Request之间数据共享 实现多个Request之间数据共享的方法很简单直观,利用一个Global对象就可以了。 复制代码 代码如下: public class Global { /// <summary> /// Global variable storing important stuff. /// </summary> static string _repairsteps; /// <summary> /// Get or set the static important data. /// </summary> public static string Repairsteps { get { return _repairsteps; } set { _repairsteps = value; } } }
2.2 Client端 2.2.1 AJAX获取 XML 复制代码 代码如下: $.ajax({ type: "GET", url: "http://localhost:3153/WebSite2/", cache: false, dataType: "xml", error:function(xhr, status, errorThrown) { alert(errorThrown+"
"+status+"
"+xhr.statusText); }, success: function(xml) { //Here we can process the xml received via Ajax }});
2.2.2 动态插入HTML List 元素 比较常见的方法是生成html stream,然后用append或html把Stream插入到DOM里面去。这样做有一个问题,如果Stream里恰好有双引号或单引号时,就要用 很多的“”分隔符,容易出错,可读性不太法,不太方便,事实上,JQuery有个create new element的功能。只要给$的输入参数包含<tag ... >时,JQuery就不会把它理解成一个selector expression, 而是把它理解成一个生成新的DOM element 。以下是一个code sample. 复制代码 代码如下: $(xml).find("step").each(function(){ var stepimagepath=$(this).text(); var stepdescription=$(this).attr("description"); additem(stepimagepath, stepdescription); }); function additem(stepimagepath, stepdescription){ $(".ad-thumbs ul").append( $("<li>").append( $("<a>").attr("href", stepimagepath).append( $("<img>").attr("src", stepimagepath).attr("alt", stepdescription) ))); }