我有一个AJAX调用一个函数:返回一个空字符串到一个AJAX请求
$('#DeviceType').change(function() {
// when the selection of the device type drop down changes
// get the new value
var devicetype = $(this).val();
$.ajax({
url: '@Url.Action("GetEquipmentCode")',
type: 'POST',
data: { deviceTypeID: devicetype },
success: function (result) {
// when the AJAX succeeds refresh the EquipmentCode text box
$('#EquipmentCode').val(result);
}
});
});
与功能是
[HttpPost]
public string GetEquipmentCode(int deviceTypeID)
{
var deviceType = _db.DeviceTypes.Single(d => d.ID == deviceTypeID);
return (deviceType.EquipmentCode != null) ?
deviceType.EquipmentCode.Code :
String.Empty;
}
但是,如果该函数返回String.Empty
字符串我真正得到在我的文本框中是“[object XMLDocument]
”。如何在我的文本框中获得空字符串的结果?
是Ajax响应应该是XML或JSON?这是来自WCF还是MVC ActionMethod? – ericb
MVC操作方法。而XML或JSON - 也许这是我应该返回而不是一个字符串? – link664