I’ve got the following JQuery code, which works fine if the VendorDropDown.ClientID is an integer, or a string that can be converted to an integer, but breaks if I try to use a string value like “Microsoft”. The PopulateSoftware function is an Asp.Net WebMethod that takes a string parameter named vendorId.
var pageUrl = '<%=ResolveUrl("~/Default.aspx")%>'
function PopulateSoftwareDropdown() {
alert('{vendorId: ' + $('#<%=VendorDropDown.ClientID%>').val() + '}');
$.ajax({
type: "POST",
url: pageUrl + '/PopulateSoftware',
data: '{vendorId: ' + $('#<%=VendorDropDown.ClientID%>').val() + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSoftwarePopulated,
failure: function (response) {
alert(response.d);
}
});
}
Use
this will effectively wrap the value with single quotes, which means that it is a string value..
more correctly it should be
This will pass as data the object we create (the
{..}part), which will be converted by jquery to the correct format (string)