Hi,
I am calling web service through jquery ajax call for the first time and getting an error. Can please somebody help me in this i would really appreciate it. Below is the code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="userNTID.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="jquery.js" type="text/javascript"></script>
<script src="JScriptuserNTID.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
Employee's NTID: <input type="text" id = "Eid" name="Employee_NTID" />
<br />
<br />
<button type = "button" id = "callingMethod" class ="start">Search</button>
</div>
</form>
</body>
</html>
Here is JScriptuserNTID.js file:
$.ajaxSetup({
cache: false
});
//var ajax_load = "<img src='loading.gif' alt='loading...' />";
// load() functions
//var loadUrl = "test.txt";
$(document).ready(function() {
$('.start').ajaxStart(function() {
alert('Triggered ajaxStart handler.');
});
$("button").click(function() {
//$("p").html(ajax_load).load(loadUrl);
//var eNtid = $("#Eid").val();
$.ajax({
type: "POST",
url: "./WebService.asmx/HelloWorld",
//data: ("Employee NTID :" + eNtid),
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert(textStatus);
},
success: function(result) {
alert("success");
}
});
});
});
Here is WebService.asmx/HelloWorld:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[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 void HelloWorld() {
Console.WriteLine( "Hello World" );
}
}