2016-07-01 1 views
0

localhost가 아닌 온라인 서버에서 json 데이터를 호출 할 때 [object object] 경고가 표시됩니다. 그것은 localhost에서 완벽하게 작동합니다. 여기 영문 코드를json 데이터를 호출 할 때 [object object] 경고가 나타납니다

$(document).ready(function() { 
     $('#btnGetEmployee').click(function() { 
      var empId = $('#txtId').val(); 
      $.ajax({ 
       url: 'WebForm1.aspx/GetEmployeeById', 
       method: 'post', 
       contentType: "application/json", 
       data: '{employeeId:' + empId + '}', 
       dataType: "json", 
       success: function (data) { 
        $('#txtName').val(data.d.Name); 
        $('#txtGender').val(data.d.Gender); 
        $('#txtSalary').val(data.d.Salary); 
       }, 
       error: function (err) { 
        alert(err); 
       } 
      }); 
     }); 
    }); 

을 그리고 여기에 확실히 일부 라인은 내가 경험이있는 사람이 내 질문에 대답 할 것이다하고자하는 온라인 서버에 대해 고려하지 않은있다

using System; 
using System.Configuration; 
using System.Data; 
using System.Data.SqlClient; 

namespace Demo 
{ 
public partial class WebForm1 : System.Web.UI.Page 
{ 
    [System.Web.Services.WebMethod] 
    public static Employee GetEmployeeById(int employeeId) 
    { 
     Employee employee = new Employee(); 

     string cs = ConfigurationManager.ConnectionStrings 
        ["DBCS"].ConnectionString; 
     using (SqlConnection con = new SqlConnection(cs)) 
     { 
      SqlCommand cmd = new SqlCommand("spGetEmployeeById", con); 
      cmd.CommandType = CommandType.StoredProcedure; 
      cmd.Parameters.Add(new SqlParameter() 
      { 
       ParameterName = "@Id", 
       Value = employeeId 
      }); 
      con.Open(); 
      SqlDataReader rdr = cmd.ExecuteReader(); 
      while (rdr.Read()) 
      { 
       employee.ID = Convert.ToInt32(rdr["Id"]); 
       employee.Name = rdr["Name"].ToString(); 
       employee.Gender = rdr["Gender"].ToString(); 
       employee.Salary = Convert.ToInt32(rdr["Salary"]); 
      } 
     } 

     return employee; 
    } 
} 

}

뒤에 코드입니다. 많은 감사합니다

+1

'alert' 대신'console.log'를 사용하면 콘솔에서 오류를 볼 수 있습니다. – Turnip

+0

@ Turner이 오류가 발생했습니다. statusText : "내부 서버 오류" –

답변

0

올바른 json 콘텐츠를 얻으려면 alert(JSON.stringify(data));을 사용해야합니다.

+0

이것은 Microsoft Edge HTTP500에서 얻는 정확한 오류 설명입니다. SERVER ERROR - 서버가 예상치 못한 조건을 충족하여 의뢰. (XHR) : POST - http://www.website.somee.com/EmployeeService.asmx/GetEmployeeById –

관련 문제