2016-07-01 12 views
0

ローカルサーバーではなくオンラインサーバーからjsonデータを呼び出すと[オブジェクトオブジェクト]警告が表示されます。これは、localhost上で完璧に動作します。ここでのaspxコードがjsonデータを呼び出すと[オブジェクトオブジェクト]が表示されます

$(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

@ urnこのエラーが発生しました statusText : "Internal Server Error" –

答えて

0

適切なjsonコンテンツを取得するには、alert(JSON.stringify(data));を使用する必要があります。

+0

これは、Microsoft Edge HTTP500から取得したエラーのコメントです。SERVER ERROR - サーバーが予期しない条件を満たしていて、要求。 (XHR):POST - http://www.website.somee.com/EmployeeService.asmx/GetEmployeeById –

関連する問題