1
我面臨的一個問題是,當我通過jquery ajax傳遞測試框值時,我無法在代碼後面看到值。無法將參數從jquery ajax傳遞給c後面的代碼#
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;
}
InsertComplaint
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功能對象的投訴沒有得到任何值而不是其舒g null。這是問題,因爲在Ajax函數中,數據的參數比具有更多屬性的投訴對象的參數少。任何人都可以幫忙 在此先感謝。
謝謝你。我花了2天時間來找出問題所在。有用。再次感謝。 –
歡迎您! – Pavlo