Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey any one please help me I am calling asp net web services using jquery ajax it's given object Object error how would I solve this



<!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>
    <title></title>
    <script src="jquery-1.11.2.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#btn').click(function () {
                var empId = $('#txtId').val();
                $.ajax({
                    url: 'EmployeeService.asmx/HelloWorld',
                    data:{ employeeId: empId },
                    mehtod: 'post',
                    dataType: 'json',
                    success: function (data) {
                        var Name = data.Name;
                        var City = data.City;
                        var Salary = data.Salary;
                        $('#txtName').val(Name);
                        $('#txtCity').val(City);
                        $('#txtSalary').val(Salary);

                    },
                    error: function (err) {
                        alert(err);
                    }



                });

            });

        });
    
    </script>
</head>
<body>

<table>
<tr>
<td>Id:-</td>
<td><input type="text" id="txtId" value="" /></td>

</tr>
<tr>
<td colspan="1"><input type="button" id="btn" value="Submit" /></td>
</tr>
</table>
<table>
<tr>
<td>Name:-</td>
<td><input type="text" id="txtName" value="" /></td>
</tr>
<tr>
<td>City:-</td>
<td><input type="text" id="txtCity" value="" /></td>
</tr>
<tr>
<td>Salary:-</td>
<td><input type="text" id="txtSalary" value="" /></td>
</tr>


</table>

</body>
</html>


What I have tried:

Hey any one please help me  I am calling asp net web services using jquery ajax it's given  object Object error how would I solve this



<pre><!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>
    <title></title>
    <script src="jquery-1.11.2.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#btn').click(function () {
                var empId = $('#txtId').val();
                $.ajax({
                    url: 'EmployeeService.asmx/HelloWorld',
                    data:{ employeeId: empId },
                    mehtod: 'post',
                    dataType: 'json',
                    success: function (data) {
                        var Name = data.Name;
                        var City = data.City;
                        var Salary = data.Salary;
                        $('#txtName').val(Name);
                        $('#txtCity').val(City);
                        $('#txtSalary').val(Salary);

                    },
                    error: function (err) {
                        alert(err);
                    }



                });

            });

        });
    
    </script>
</head>
<body>

<table>
<tr>
<td>Id:-</td>
<td><input type="text" id="txtId" value="" /></td>

</tr>
<tr>
<td colspan="1"><input type="button" id="btn" value="Submit" /></td>
</tr>
</table>
<table>
<tr>
<td>Name:-</td>
<td><input type="text" id="txtName" value="" /></td>
</tr>
<tr>
<td>City:-</td>
<td><input type="text" id="txtCity" value="" /></td>
</tr>
<tr>
<td>Salary:-</td>
<td><input type="text" id="txtSalary" value="" /></td>
</tr>


</table>

</body>
</html>
Posted
Updated 29-Jun-20 0:54am

1 solution

When you have one of these errors, it is best to give the actual exception. A quick scan found a type
mehtod: 'post'
should be
method: 'post'
 
Share this answer
 
Comments
satyanand mishra 29-Jun-20 7:50am    
Thanks for reply
but it's still give same exception [object:Object]
my Web service code is


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace JequeryDemo4
{
///
/// Summary description for EmployeeService
///

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 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
{

[WebMethod]
public Employee HelloWorld(int employeeId)
{
Employee emp = new Employee();
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Emp"].ConnectionString);
SqlCommand cmd = new SqlCommand("spGet", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@Id", SqlDbType.Int).Value = employeeId;
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
emp.Id =Convert.ToInt32(dr["Id"]);
emp.Name = dr["Name"].ToString();
emp.City = dr["City"].ToString();
emp.Salary =Convert.ToInt32(dr["Salary"]);
}
return emp;
}
}
}
MadMyche 29-Jun-20 10:38am    
What is the JSON being returned?
satyanand mishra 30-Jun-20 11:40am    
Thank you very Much i did it

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900