try this.. :)
Javascript
function GetName() {
$.ajax({
type: "POST",
url: "Default.aspx/GetData",
contentType: "application/json;charset=utf-8",
data: {},
dataType: "json",
success: function (data) {
alert(data.d);
},
error: function (result) {
alert("error")
}
});
}
HTML
<span onclick="GetName()">Call Web Method</span>
C#
[WebMethod]
public static string GetData()
{
string name= "My name is Nirav Prabtani";
return name;
}