how to call webmethod with parameter
<asp:Label ID="Label1" runat="server" Text="2 Js call">HHHH
<asp:Label ID="Label2" runat="server" Text="">
// show1() and show2() call in Label1//
========================================================================
function show1() {
var lb = document.getElementById('Label1').innerHTML;
document.getElementById("Label2").innerHTML = lb;
}
function show2() {
$.ajax({
type: "POST",
url: "JS2.aspx/GetCurrentTime",
data: '{name: "' + document.getElementById("Label2").innerHTML + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
}
function OnSuccess(response) {
alert(response.d);
}
============================================================
[System.Web.Services.WebMethod]
public static string GetCurrentTime(string name)
{
return "Hello " + name + Environment.NewLine + "The Current Time is: "
+ DateTime.Now.ToString();
}
===============================
PROBLEM is here
data: '{name: "' + document.getElementById("Label2").innerHTML + '" }'
I did not pass Label2 value here , so its show undefiend.Pls help me