ローカルサーバーではなくオンラインサーバーから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;
}
}
}
の背後にあるコードがありますが、私は経験を持つ誰かが私に答えるたいオンラインサーバーのために考慮されていません。 多くのありがとう
'alert'ではなく' console.log'を使うと、コンソールでエラーを見ることができます。 – Turnip
@ urnこのエラーが発生しました statusText : "Internal Server Error" –