我有功能,我正在尝试将返回值附加到下拉列表,但它根本没有帮助。
这是我的功能
function GetNames(FROM,TO) {
var inputObject = {};
inputObject.FROM = FROM;
inputObject.TO = TO;
$.ajax({
type: "POST",
url: "../WebService.asmx/getName",
data: {from : inputObject.FROM ,to : inputObject.TO},
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
success: function (msg) {
$.each(msg.d, function (k, value) {
$('#ddlName').append("<option value='" + value + "'>" + value + " </option>");
});
},
error: function (errMsg) {
alert(errMsg);
}
});
}
我也将数据参数更改为此值,但它们没有帮助
1) data: JSON.stringify(inputObject),
2) data: {'from=' : inputObject.FROM, 'to=' : inputObject.TO},
3) data: {'from' : inputObject.FROM, 'to' : inputObject.TO},
这些变化都没有帮助。
FROM 和 TO 是我测试 webservice getName 方法及其工作正常的日期。但是这个javascript方法不断出错:函数(errMsg)和消息出现“对象:对象”
网络服务方法:
[WebMethod]
public List<string> getName(string from,string to)
{
List<string> bdnames= new List<string>();
try
{
DataSet ds = null;
SqlParameter[] sqlparams = new SqlParameter[2];
sqlparams[0] = new SqlParameter("@FROM", SqlDbType.DateTime);
sqlparams[0].Direction = ParameterDirection.Input;
sqlparams[0].Value = Convert.ToDateTime(from);
sqlparams[1] = new SqlParameter("@TO", SqlDbType.DateTime);
sqlparams[1].Direction = ParameterDirection.Input;
sqlparams[1].Value = Convert.ToDateTime(to);
ds = SqlHelper.ExecuteDataset(usmHelper.ConnectionString, CommandType.StoredProcedure, "rep_getBDMs", sqlparams);
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
bdnames.Add(ds.Tables[0].Rows[i]["UUMM"].ToString());
}
}
catch(Exception ex)
{
}
finally
{
}
return bdnames;
}
Web 服务返回值
<?xml version="1.0" encoding="utf-8" ?>
- <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<string>Samuel</string>
<string>Chetna</string>
<string>Chris</string>
<string>Mily</string>
<string>tuff</string>
<string>Prasad</string>
<string>Ram</string>
<string>Gary</string>
<string>MarkTaylor</string>
<string>Kenn</string>
</ArrayOfString>