我之前在本網站上詢問過有關ajax客戶端 - 服務器通信的問題。ajax客戶端 - 服務器通信
我得到了很多幫助。但仍然無法解決,所以重新提出這個問題。
我嘗試從我的JavaScript頁面發送存儲在變量'mem_ID'中的值... Default.aspx到我的服務器端 - Default.aspx.cs頁面。
的Javascript: -
<asp:Button ID="Button6" runat="server" BackColor="Silver"
onclientclick="store_memID()" style="margin-left: 20px" Text="Submit"
Width="102px" Font-Bold="True" Height="28px" />
<script type = "text/javascript" src ="http://code.jquery.com/jquery-1.9.0.min.js"> </script>
<script type = "text/javascript">
// Function to caputure client-input- Member_ID.
function store_memID() {
// 'TextBox3' is the server side ID. To get the client side ID we do the following:-
mem_ID = document.getElementById('<%=TextBox3.ClientID%>').value;
//return confirm('TimeLine is displayed for: ' + mem_ID);
ajax();
}
function ajax(){
$.ajax({
url: 'Default.aspx/MyMethod',
type: 'POST',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ memID: mem_ID }),
success: function (result) {
alert(result.d);
}
});
}
</script>
服務器端: -
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
// Defining a page method.
[WebMethod]
public static string MyMethod(string mem_ID)
{
return string.Format("Thanks for calling me with id: " + mem_ID);
}
` more code here`....
不過,我仍然沒有得到從服務器返回的任何答覆。我期待着從服務器端返回「謝謝帶ID:.....」。有任何想法嗎?
我在服務器端的響應行MyMethod中添加了一個斷點,但沒有命中。所以我假設這條線甚至沒有被遍歷。
我是新來的Asp.net和Ajax。並需要關於此主題的幫助。
仍然沒有迴音,但... – Philo
非常感謝大家,你們非常有幫助。感謝讓我開始達林!和Muthuram! – Philo