i'm tried to implement ajax using jQuery.Its my first time to use ajax.so in a button click i need to display the current datetime. For this, i write the below code
//==============aspx page===============
<script type="text/javascript">
$(document).ready(function (){
var Button1 = $("#Button1");
var Label1 = $("#Label1");
Button1.click(function (){
$.ajax({
type: "POST",
url: "/myownajax14/WebService/WebService1.asmx/GetDateTime",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
$("#Label1").text(msg.d);
//alert('hi');
},
error:alert('error');
});
});
});
//================asmx.cs page===========
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string GetDateTime()
{
return DateTime.Now.ToString();
}
}
My problem is,it doesn't give the answer..and it doesn't show any error.Have any mistake in this code?Please help me..
Button1.click(function (e){ e.preventDefault()and use error functionerror:function(){alert('error')};console.log(msg);