【发布时间】:2017-07-01 02:51:17
【问题描述】:
我面临一个问题,当我通过 jquery ajax 传递测试框值时,我看不到后面代码中的值。
function CreateComplaint(){
var category = $('#ddlCompCategory') .val();
var name = $('#txtCompUserName') .val();
var subject = $('#txtCompSub') .val();
var mobile = $('#txtCompMobileNo') .val();
var address = $('#txtaCompAddr') .val();
var email = $('#txtCompEmail') .val();
$('#spinnerAddComplaint').show();
CreateComplaintXHR(
'/api/Complaints/CreateComplaint',
{
Token : RBApp.Token,
CategoryId : category,
UName : name,
Subject : subject,
Mobile : mobile,
Email : email,
Address : address
}, ....}
ajax 函数:
function CreateComplaintXHR(url, data, success, error, alWaysCallback) {
$.ajax({
url: url,
type: 'POST',
dataType: 'json',
data: data,
success: function (data, textStatus, jqXHR) {
if (success)
success(data, textStatus, jqXHR);
},
error: function (jqXHR, textStatus, errorThrown) {
if (error)
error(jqXHR, textStatus, errorThrown);
}
}).always(function () {
});
}
后面的代码:
[HttpPost]
[ActionName ( "CreateComplaint" )]
public ResponseModel InsertComplaintMethod(InsertComplaint Complaint)
{
log .Debug ( "Create Complaint request received : " );
log .Debug ( "Request params : " + Complaint .Serialize() );
User user = loadUser ( Complaint .Token );
ComplaintsAdapter adapter = new ComplaintsAdapter ( user );
ResponseModel response = adapter .CreateComplaintOrSuggestion ( Complaint );
return response;
}
插入投诉
public class InsertComplaint
{
//public string Token { get; set; }
public string Lat = "0"; //{ get; set; }
public string Lng = "0"; //{ get; set; }
public string deviceID = "0";
public string complaintSubject { get; set; }
public string complaintText { get; set; }
public string name { get; set; }
public string phoneNumber { get; set; }
public string attachements = null;
}
在 insertComplaintMethod 函数对象中,投诉没有得到任何值,而是显示为 null。这是问题吗,因为在 ajax 函数数据中的参数比在具有更多属性的投诉对象中少。任何人都可以提供帮助。 提前致谢。
【问题讨论】:
标签: c# jquery ajax web-services rest