Asp.net jquery ajax call -
i practicing jquery ajax call. happens when run project gives internal server error 500. error means , how encounter error?
i created sample project in added code:
namespace sample { public partial class jqajaxcall : system.web.ui.page { protected void page_load(object sender, eventargs e) { if (!ispostback) getdatetime(); } [webmethod] private static string getdatetime() { return datetime.now.tostring(); } } }
my aspx code file:
<script type="text/javascript" src="library/js/jquery-1.9.1-min.js"></script> <script type="text/javascript"> $(document).ready(function () { // add page method call onclick handler div. $("#result").click(function () { $.ajax({ type: "post", url: "jqajaxcall.aspx/getdatetime", data: "{}", contenttype: "application/json; charset=utf-8", datatype: "json", success: function (msg) { // replace div's content page method's return. $("#result").text(msg.d); } }); }); }); </script> </head> <body> <form id="form1" runat="server"> <div id="result"> click here time.</div> </form> </body> </html>
define function public...to access jquery this
[webmethod] //define function public.... public static string getdatetime() { return datetime.now.tostring(); }
Comments
Post a Comment