私はデータベースにデータを挿入するためにwebserviceを書いており、WebサービスはURL "http:\\localhost\Webservice.asmx"
を使ってサービスにアクセスすると動作します.jquery ajaxを使って同じURLを呼び出した場合は、(500)Internal serverを返します。これは私のソースコードです。jqueryを使用してWebサービスを呼び出すと、500の内部サーバーエラーが返されますか?
//コードは、顧客データを挿入するためにお客様詳細
$('#submitAddDetail').on('click', function (e) {
//alert('Hello World');
var custId = $(".addcustomer-body #custId").val();
var custName = $(".addcustomer-body #custName").val();
var custCity = $(".addcustomer-body #custCity").val();
var custPostalCode = $(".addcustomer-body #custPostalCode").val();
var custCountry = $(".addcustomer-body #custCountry").val();
var custPhone = $(".addcustomer-body #custPhone").val();
var custFax = $(".addcustomer-body #custFax").val();
debugger;
//alert(custName);
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: "json",
url: "WebService.asmx/AddCustomers",
data: "{ 'sCustomerId': '" + custId + "','sCompanyName': '" + custName + "','sCity':'" + custCity + "','sPostalCode':'" + custPostalCode + "','sCountry':'" + custCountry + "','sPhone:'" + custPhone + "','sFax':'" + custFax + "'}",
success: function (data) {
debugger;
if (data.d == 'true') {
location.reload();
}
else {
debugger;
alert('Error in Inserting data');
}
}
});
});
//私のWebサービスを挿入します。 [WebMethod属性]
public string AddCustomers(string sCustomerId, string sCompanyName, string sCity, string sPostalCode, string sCountry, string sPhone, string sFax)
{
string msg = string.Empty;
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
string sQuery = "INSERT INTO Customers (CustomerID,CompanyName,City,PostalCode,Country,Phone,Fax)VALUES" +
"(@CustomerID,@CompanyName,@City,@PostalCode,@Country,@Phone,@Fax)";
using (SqlCommand cmd = new SqlCommand(sQuery))
{
cmd.Connection = con;
cmd.Parameters.AddWithValue("@CustomerID", sCustomerId);
cmd.Parameters.AddWithValue("@CompanyName", sCompanyName);
cmd.Parameters.AddWithValue("@City", sCity);
cmd.Parameters.AddWithValue("@PostalCode", sPostalCode);
cmd.Parameters.AddWithValue("@Country", sCountry);
cmd.Parameters.AddWithValue("@Phone", sPhone);
cmd.Parameters.AddWithValue("@Fax", sFax);
con.Open();
int i = cmd.ExecuteNonQuery();
if (i == 1)
{
msg = "true";
}
else
{
msg = "false";
}
}
}
return msg;
}//End
私は事前にこのissue.Thanksの解決にあなたの助けを必要としています。