我的数据参数如下所示:
data: '{"originfieldTitle":"' + $("#txt-central-name").val() + '","newfieldTitle":"' + $("#txt-local-name").val() + '","originfieldcolumn":"' + $("#txt-central-columnname").val() + '","countryId":"' + $("#business-drop-selected").val() + '"}',
在WCF服务中,mthod看起来像:
[SharePointPermission(SecurityAction.Demand, ObjectModel = true)]
[WebInvoke(Method = "POST", UriTemplate = "/SaveMapping", BodyStyle = WebMessageBodyStyle.WrappedRequest, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)]
public PortalResponse SaveMapping(string originfieldTitle, string newfieldTitle, string originfieldcolumn, string countryId)
{
}
但是我在ajax中总是得到错误的请求它会进入错误回调。 当我发送一个参数时,我可以在wcf的调试模式下看到数据。 任何人都可以建议吗?我认为发送数据时遇到的一些问题可能是逗号。
AJAX
$.ajax({
type: "POST",
url: url,
data: '{"originfieldTitle":"' + $("#txt-central-name").val() + '","newfieldTitle":"' + $("#txt-local-name").val() + '","originfieldcolumn":"' + $("#txt-central-columnname").val() + '","countryId":"' + $("#business-drop-selected").val() + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
processData: false,
success: function (response) {
if (!response.HasError) {
StaplesAca.UnLockUi();
MappingTableAdvanced.Reload();
MappingFeatures.ClearNewFormData();
} else {
bootbox.alert("Something went wrong. Please try again later! Error: " + response.Message);
StaplesAca.UnLockUi();
}
},
error: function () {
bootbox.alert("Something went wrong. Please try again later!");
StaplesAca.UnLockUi();
}
});
答案 0 :(得分:0)
嘿,因为你的接收器有BodyStyle = WebMessageBodyStyle.WrappedRequest 因此它应该是一个包装请求请使用ajax中的数据参数,如下所示:
data: JSON.stringify({originfieldTitle: $("#txt-central-name").val(),newfieldTitle: $("#txt-local-name").val() ,originfieldcolumn: $("#txt-central-columnname").val()
,countryId: $("#business-drop-selected").val()}),