2011-04-23 72 views
0

我在運行下面的腳本時遇到問題。我試圖調用一個服務器端方法的按鈕點擊使用jQuery。但它不起作用。我既沒有成功也沒有失敗的提醒檢查腳本。請幫忙。jquery的問題

$(document).ready(function() { 
var xml=""; // Scope limit covered but not working 
    $('#<%=btnSave.ClientID %>').click(function(event) { 
    xml = "<schedule>"; 
    $("#selectedcolumns").find("tr").each(function() { 
     xml += "<data>"; 
     xml += $(this).find("td").eq(1).html() + "\n"; 
     xml += "</data>"; 
    }); 
    xml += "</schedule>"; 


    //PAgeMethod 
    PageMethods.GetCustomer(
     xml, 
     function(result) { 
      alert('success:' + result); 
     }, 
     function(result) { 
      alert('error:' + result.get_message()); 
     }); 

    alert(xml); 

    }) 
}); 

在代碼隱藏:

[WebMethod] 


private void GetCustomer(string NoOfRecords) //just need to reach here. 


    { 
    xmlfile(NoOfRecords); 
    } 
+0

嘗試使用Firebug:HTTP:// getfirebug.com/幫助調試你的javascript和post/respoonses這對於排查ajax funcationality是至關重要的。 – 2011-04-23 03:14:00

回答

0

WebMethod的需要被聲明爲static。包含從jQuery調用服務器端方法的Here is a good guide

+0

我在做同樣的文章,並且遇到了一些與json數據有關的問題。我是jquery的新手,不知道如何解決問題:( – NewBie 2011-04-23 02:57:32

+0

).asmx中的WebMethod無需聲明爲靜態(僅適用於.aspx中的)。 – 2011-04-23 03:12:36

+0

我的歉意應該更接近我不知道它沒有使用.aspx代碼「。 – 2011-04-23 04:39:02

1

這是XML值的範圍界定問題(您可以在回調的範圍內聲明它 - 因此它是不可見的出一側功能

$(document).ready(function() { 
    var xml = ""; 

    $('#<%=btnSave.ClientID %>').click(function(event) { 
    xml = "<schedule>"; 
    $("#selectedcolumns").find("tr").each(function() { 
     xml += "<data>"; 
     xml += $(this).find("td").eq(1).html() + "\n"; 
     xml += "</data>"; 
    }); 
    xml += "</schedule>"; 

//This method is defined in the codebehind 
    PageMethods.GetCustomer(
    xml, 
    function(result) { 
     alert('success:' + result); 
    }, 
    function(result) { 
     alert('error:' + result.get_message()); 
    }); 

    alert(xml); 
    }); 
}); 
+0

試過了,似乎沒有工作:( – NewBie 2011-04-23 02:52:52

+0

行,然後更新你的代碼,並顯示你已經嘗試過。同時顯示原始帖子中缺少的「PageMethods.GetCustomer」代碼。 – Hogan 2011-04-23 02:56:44

+0

我認爲頁面方法代碼在文章中。我在我的頁面中只做了很多,不知道是否應該編寫任何其他代碼來完成這項工作。 – NewBie 2011-04-23 03:03:57