ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved.Call asmx Web Service using jQuery AJAX in ASP.Net<p>Hi <a class="username" rel="Omega">Omega</a>,</p> <p>Refer below code.</p> <p><strong><span style="text-decoration: underline;">SQL</span></strong></p> <pre class="brush: sql">CREATE PROCEDURE spGetEmployeeById @Id INT AS BEGIN SELECT * FROM Employee WHERE Id = @Id END</pre> <p><span style="text-decoration: underline;"><strong>EmployeeService.asmx</strong></span></p> <pre class="brush: csharp">using System; using System.Configuration; using System.Data; using System.Data.SqlClient; using System.Web.Services; /// &lt;summary&gt; /// Summary description for EmployeeService /// &lt;/summary&gt; [WebService(Namespace = &#34;http://tempuri.org/&#34;)] [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 EmployeeService : System.Web.Services.WebService { public EmployeeService() { //Uncomment the following line if using designed components //InitializeComponent(); } [WebMethod] public Employee GetEmployeeById(int employeeId) { Employee employee = new Employee(); string cs = ConfigurationManager.ConnectionStrings[&#34;constr&#34;].ConnectionString; using (SqlConnection con = new SqlConnection(cs)) { SqlCommand cmd = new SqlCommand(&#34;spGetEmployeeById&#34;, con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.Add(new SqlParameter(&#34;@Id&#34;, employeeId)); con.Open(); SqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { employee.Id = Convert.ToInt32(rdr[&#34;Id&#34;]); employee.Name = rdr[&#34;Name&#34;].ToString(); employee.Gender = rdr[&#34;Gender&#34;].ToString(); employee.Salary = Convert.ToInt32(rdr[&#34;Salary&#34;]); } } return employee; } public class Employee { public int Id { get; set; } public string Name { get; set; } public string Gender { get; set; } public int Salary { get; set; } } } </pre> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <p>&nbsp;</p> <pre class="brush: html">&lt;html xmlns=&#34;http://www.w3.org/1999/xhtml&#34;&gt; &lt;head runat=&#34;server&#34;&gt; &lt;title&gt;&lt;/title&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(document).ready(function () { $(&#39;#btnGetEmployee&#39;).click(function () { var empId = $(&#39;#txtId&#39;).val(); $.ajax({ url: &#39;&lt;%= ResolveUrl(&#34;EmployeeService.asmx/GetEmployeeById&#34;)%&gt;&#39;, data: { employeeId: empId }, type: &#39;post&#39;, dataType: &#39;xml&#39;, success: function (data) { var jQueryXml = $(data); $(&#39;#txtName&#39;).val(jQueryXml.find(&#39;Name&#39;).text()); $(&#39;#txtGender&#39;).val(jQueryXml.find(&#39;Gender&#39;).text()); $(&#39;#txtSalary&#39;).val(jQueryXml.find(&#39;Salary&#39;).text()); }, error: function (err) { alert(err.responseText); } }); return false; }); }); &lt;/script&gt; &lt;/head&gt; &lt;body style=&#34;font-family: Arial&#34;&gt; &lt;form id=&#34;form1&#34; runat=&#34;server&#34;&gt; &lt;div&gt; ID :&lt;asp:TextBox ID=&#34;txtId&#34; runat=&#34;server&#34; Style=&#34;width: 100px&#34;&gt;&lt;/asp:TextBox&gt; &lt;asp:Button ID=&#34;btnGetEmployee&#34; runat=&#34;server&#34; Text=&#34;Get Employee&#34; /&gt; &lt;br /&gt; &lt;br /&gt; &lt;table border=&#34;1&#34; style=&#34;border-collapse: collapse&#34;&gt; &lt;tr&gt; &lt;td&gt; Name &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txtName&#34; runat=&#34;server&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; Gender &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txtGender&#34; runat=&#34;server&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td&gt; Salary &lt;/td&gt; &lt;td&gt; &lt;asp:TextBox ID=&#34;txtSalary&#34; runat=&#34;server&#34;&gt;&lt;/asp:TextBox&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt;</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><img src="https://imgur.com/ZKEejC1.gif" alt="" width="260" height="237" /></p>https://www.aspforums.net:443/Threads/378302/Call-asmx-Web-Service-using-jQuery-AJAX-in-ASPNet/https://www.aspforums.net:443/Threads/378302/Call-asmx-Web-Service-using-jQuery-AJAX-in-ASPNet/Mon, 17 Sep 2018 06:22:59 GMT