I have a requirement which I need to call web service using jQuery AJAX call. For that I have created WebService and created one client website. Unfortunately, I am not able to call this. The AJAX call is not triggering at all.
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
public WebService()
{
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string getMessage(string name)
{
return "Hello " + name;
}
}
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="GetMessage" Style="height: 26px"/>
<asp:Label ID="Label1" runat="server" Font-Bold="True"></asp:Label>
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>.
$(document).ready(function () {
$('#Button1').click(function () {
alert(1);
$.ajax({
type: 'post',
CORS: true,
url: 'http://localhost/WebService/Hello.asmx?op=getMessage',
contentType: "application/xml",
data: { name: 'aa' },
success: function (d) {
alert(d);
},
failure: function (response) {
debugger;
alert(response.d);
}
});
});
});
I am trying to access the web service from the client application.I am passing the ASMX file in URL path. I have given service reference also. Unfortunately it is not triggering. Is there any mistake in the AJAX? Can anyone help on this? It's not showing any errors.


CORSin Jquery.ajax, but there is option forcrossDomainCORS: true,in Jquery AJAX.