当我将参数传递给Web方法的AJAX请求时,我遇到了问题。 这显示错误"无效的Web服务调用,缺少参数值:' getQualityDetailList' &#34 ;. AJAX请求在下面..
SaveProductComplaint: function
(failureCB,getQualityDetailList,getShortageDetailList,getPackageDetailList) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "ProductComplaint.aspx/SaveProductComplaint",
dataType: "json",
data: JSON.stringify(ProductComplaintPage.ajaxDataObject,{'getQualityDetailList': getQualityDetailList ,'getShortageDetailList': getShortageDetailList ,'getPackageDetailList': getPackageDetailList }),
success: function (msg) {
if (msg !== null && msg.d !== null && msg.d !== "null") {
var result = $.parseJSON(msg.d);
if (result.Exception) {
if (result.Type === GlobalMsgResource.Type_Error) {
ShowErrorMessage(result.Message);
} else if (result.Type === GlobalMsgResource.Type_Warning) {
ShowWarningMessage(result.Message);
}
else if (result.Type == GlobalMsgResource.Session_Timout_Error) {
ShowConfirm('Session timeout, please re-login.', {
type: 'error',
title: 'Error',
showCancelButton: false,
confirmButtonMethod: function () {
window.location = "~/Login.aspx";
}
});
}
}
else if (result) {
ShowConfirm('Your complaint against Complaint ID ' + result + ' has been registered...', {
type: 'success',
title: 'Success',
showCancelButton: false,
confirmButtonMethod: function () {
successCB(result);
showLoader(false);
//ProductComplaintPage.view.ResetControls();
}
});
}
} else {
ShowErrorMessage(GlobalMsgResource.Something_Went_Wrong);
}
showLoader(false);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
failureCB(XMLHttpRequest, textStatus, errorThrown);
showLoader(false);
}
});
}
这是函数,其中我为AJAX请求中的传递参数赋值。
addProductComplaint: function () {
//if ($(ProductComplaintPage.controlIds.Form).valid()) {
ProductComplaintPage.ajaxDataObject = {
productcomplaintentity: {
ProductComplaintId: $(ProductComplaintPage.controlIds.txtProductComplaintId).val(),
CustomerId: $(ProductComplaintPage.controlIds.txtCustomerId).val(),
ComplaintPriority: $(ProductComplaintPage.controlIds.ddlComplaintpriority + ' OPTION:selected').text()
}
};
var table1 = $(ProductComplaintPage.controlIds.dtQualityIssueDetail).DataTable();
var getQualityDetailList = [];
var qualityissuesallrows = table1.rows().nodes();
if (qualityissuesallrows.length > 0) {
$.each(qualityissuesallrows, function (index, value) {
var QualityIssueDetailEntity = {};
QualityIssueDetailEntity.barCode = $(this).find("td").eq(1).html();
QualityIssueDetailEntity.ProductComplaintId = $(ProductComplaintPage.controlIds.txtProductComplaintId).val();
QualityIssueDetailEntity.ItemName = $(this).find("td").eq(2).html();
QualityIssueDetailEntity.RatioOfProblem = $(this).find("td").eq(3).html();
QualityIssueDetailEntity.Reason = $(this).find("td").eq(4).html();
QualityIssueDetailEntity.Suggestion = $(this).find("td").eq(5).html();
getQualityDetailList.push(QualityIssueDetailEntity);
});
}
var table1 = $(ProductComplaintPage.controlIds.dtShortageIssueDetail).DataTable();
var getShortageDetailList = [];
var shortageissueallrows = table1.rows().nodes();
if (shortageissueallrows.length > 0) {
$.each(shortageissueallrows, function (index, value) {
var ShortageIssueDetailEntity = {};
ShortageIssueDetailEntity.barCode = $(this).find("td").eq(1).html();
ShortageIssueDetailEntity.ProductComplaintId = $(ProductComplaintPage.controlIds.txtProductComplaintId).val();
ShortageIssueDetailEntity.ItemName = $(this).find("td").eq(2).html();
ShortageIssueDetailEntity.ShortageSinceInMonth = $(this).find("td").eq(3).html();
getShortageDetailList.push(ShortageIssueDetailEntity);
});
}
var table1 = $(ProductComplaintPage.controlIds.dtPackageIssueDetail).DataTable();
var getPackageDetailList = [];
var packageissueallrows = table1.rows().nodes();
if (packageissueallrows.length > 0) {
$.each(packageissueallrows, function (index, value) {
var PackageIssueDetailEntity = {};
PackageIssueDetailEntity.barCode = $(this).find("td").eq(1).html();
PackageIssueDetailEntity.ProductComplaintId = $(ProductComplaintPage.controlIds.txtProductComplaintId).val();
PackageIssueDetailEntity.ItemName = $(this).find("td").eq(2).html();
PackageIssueDetailEntity.NoOfPieces = $(this).find("td").eq(3).html();
PackageIssueDetailEntity.Problem = $(this).find("td").eq(4).html();
PackageIssueDetailEntity.Suggestion = $(this).find("td").eq(5).html();
getPackageDetailList.push(PackageIssueDetailEntity);
});
}
ProductComplaintPage.modelView.SaveProductComplaint(getQualityDetailList,getShortageDetailList,getPackageDetailList);
// if(getQualityDetailList != 0 && getQualityDetailList != '' && getQualityDetailList != null){
//
// }
// else if(getShortageDetailList != 0 && getShortageDetailList != '' && getShortageDetailList != null)
// {
// ProductComplaintPage.modelView.SaveShortageProductComplaint(getShortageDetailList);
// }
// else if(getPackageDetailList != 0 && getPackageDetailList != '' && getPackageDetailList != null)
// {
// ProductComplaintPage.modelView.SavePackageProductComplaint(getPackageDetailList);
// }
//}
}
这是我的网络方法......
[WebMethod]
[ScriptMethod]
public static string SaveProductComplaint(ProductComplaintMasterEntity productcomplaintentity, List<ProductComplaintDetailQualityEntity> getQualityDetailList, List<ProductComplaintDetailShortageIssueEntity> getShortageDetailList, List<ProductComplaintDetailPackingEntity> getPackageDetailList)
{
ILog logger = log4net.LogManager.GetLogger("ErrorLog");
try
{
if (HttpContext.Current.Session["UserID"] == null)
{
SessionSpecificException sse = new SessionSpecificException() { Reason = "Session timeout, please re-login." };
throw new SessionSpecificException();
}
clsProductComplaintMaster obj = new clsProductComplaintMaster();
DataTable dt = new DataTable();
int max = obj.GetMaxProductComplaintId();
productcomplaintentity.ProductComplaintId = max;
productcomplaintentity.DataEntryUserID = HttpContext.Current.Session["UserID"].ToString().ToUpper();
if (obj.Save(0, productcomplaintentity))
{
if (Convert.ToBoolean(ConfigurationSettings.AppSettings["IsAllowSMS"]))
{
nSendSMS(productcomplaintentity.CustomerId, productcomplaintentity.ProductComplaintId);
}
return max.ToString();
}
else if (getQualityDetailList.Count > 0 )
{
using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["GTBSConnectionString"].ConnectionString))
{
connection.Open();
SqlTransaction transaction = connection.BeginTransaction();
using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.Default, transaction))
{
bulkCopy.BatchSize = 100;
bulkCopy.DestinationTableName = "dbo.CRM_ProductComplaintDetailQualityTAB";
try
{
var reducedList = getQualityDetailList.Select(x => new { x.ProductComplaintId, x.Barcode, x.RatioOfProblem, x.Reason, x.Suggestion }).ToList();
bulkCopy.WriteToServer(reducedList.AsDataTable());
transaction.Commit();
}
catch (Exception)
{
transaction.Rollback();
connection.Close();
}
}
}
}
else if (getShortageDetailList.Count > 0)
{
using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["GTBSConnectionString"].ConnectionString))
{
connection.Open();
SqlTransaction transaction = connection.BeginTransaction();
using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.Default, transaction))
{
bulkCopy.BatchSize = 100;
bulkCopy.DestinationTableName = "dbo.CRM_ProductComplaintDetailShortageIssueTAB";
try
{
var reducedList = getShortageDetailList.Select(x => new { x.ProductComplaintId, x.Barcode, x.ShortageSinceInMonth, x.OrderQuantity, x.ShortageDate }).ToList();
bulkCopy.WriteToServer(reducedList.AsDataTable());
transaction.Commit();
}
catch (Exception)
{
transaction.Rollback();
connection.Close();
}
}
}
}
else if (getPackageDetailList.Count > 0)
{
using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["GTBSConnectionString"].ConnectionString))
{
connection.Open();
SqlTransaction transaction = connection.BeginTransaction();
using (var bulkCopy = new SqlBulkCopy(connection, SqlBulkCopyOptions.Default, transaction))
{
bulkCopy.BatchSize = 100;
bulkCopy.DestinationTableName = "dbo.CRM_ProductComplaintDetailPackingTAB";
try
{
var reducedList = getPackageDetailList.Select(x => new { x.ProductComplaintId, x.Barcode, x.Problem, x.Suggestion, x.NoOfPieces }).ToList();
bulkCopy.WriteToServer(reducedList.AsDataTable());
transaction.Commit();
}
catch (Exception)
{
transaction.Rollback();
connection.Close();
}
}
}
}
return "";
}
catch (SessionSpecificException sse)
{
HttpContext.Current.Session.Abandon();
HttpContext.Current.Session.Contents.RemoveAll();
System.Web.Security.FormsAuthentication.SignOut();
return JsonConvert.SerializeObject(new
{
Exception = true,
Message = sse.Message,
Type = "Redirect"
});
}
catch (UserSpecificException use)
{
return JsonConvert.SerializeObject(new
{
Exception = true,
Message = use.Message,
Type = "Error"
});
}
catch (Exception ex)
{
return JsonConvert.SerializeObject(new
{
Exception = true,
Message = GlobalMsgResource.Something_Went_Wrong,
Type = "Error"
});
}
return JsonConvert.SerializeObject("failed");
}