Hello Everyone
I have an Asp .Net web form on which there a button control and on clicking that I am returning string welcome message using jQuery Ajax. On button click jQuery works fine but Ajax call not working.
Please help me out below is my code.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="hhu.aspx.cs" Inherits="aatish.hhu" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="Scripts/jquery-3.4.1.min.js"></script>
<script type="text/javascript">
function SaveThis() {
alert("ByJquery");
$.ajax({
type: "POST",
url: "huhu.aspx/MyAjax",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert("eee");
},
error: function (d) {
alert(d.d);
}
});
}
function OnSuccess(response) {
alert(response.d);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="button" id="btn" value="click here" onclick="SaveThis()" />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace aatish
{
public partial class hhu : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
[WebMethod]
public static string MyAjax()
{
return "Hello";
}
}
}