私は、jqueryからwebmethodに値を渡そうとしています。しかし1つのパスの値webmethodが開始されないとき。そして、渡された値のコードを削除すると、正しく動作するようになります。問題は何ですか? JSコード。Webmethodが動作しなくなる
$(function() {
$.ajax({
type: "POST",
url: "ContryCityDDL.aspx/GetCountry",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
var ddlcontry = $("[id*=ddlcontry]");
ddlcontry.empty().append('<option selected="selected" value="0">Please select</option>');
$.each(r.d, function() {
ddlcontry.append($("<option></option>").val(this['Value']).html(this['Text']));
});
}
});
$("#ddlcontry").change(function() {
alert($('option:selected', $(this)).val());
var countyId = $(this).val();
$("#HiddenField1").val($('option:selected', $(this)).val());
$.ajax({
type: "POST",
url: "ContryCityDDL.aspx/GetCity&countryId='"+countryId+"'",
data: '{}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (r) {
var ddlcity = $("[id*=ddlcity]");
ddlcity.empty().append('<option selected="selected" value="0">Please select</option>');
$.each(r.d, function() {
ddlcity.append($("<option></option>").val(this['Value']).html(this['Text']));
});
}
});
});
});
C#
[WebMethod]
public static List<ListItem> GetCity(string countryId)
{
string constrng;
string query = "Select CityId,CityName From City";
//string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
constrng = "Data Source=(LocalDB)\\v11.0;AttachDbFilename='C:\\Users\\Abdul Basit Mehmood\\Desktop\\DropdownAJAX\\DropdownAJAX\\App_Data\\ContryCity.mdf';Integrated Security=True";
using (SqlConnection con = new SqlConnection(constrng))
{
using (SqlCommand cmd = new SqlCommand(query))
{
List<ListItem> customers = new List<ListItem>();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
con.Open();
using (SqlDataReader sdr = cmd.ExecuteReader())
{
while (sdr.Read())
{
customers.Add(new ListItem
{
Value = sdr["CityId"].ToString(),
Text = sdr["CityName"].ToString()
});
}
}
con.Close();
return customers;
}
}
}
iは、C#コードから「列countryId'
及び() `VAR countyId = $(この).valを取り除きます。コードが正しく実行JSから& countryId =「『+ countryId +』」」。
、ddlcontry変更機能でこれを試してみてくださいGetCity(string countryId)が機能しない理由関数内の引数を読みたいときにissuとは何ですか? jsの変更は何の違いもありません –