我在上传按钮的click事件中包含以下Javascript代码,我想记录xAPI语句。我在我的Admin / NewStatement方法上放了一个断点,虽然它正在点击它,但是在我逐步通过断点之前,页面总是显示错误消息。为什么这一直都在失败?
var postData = {
'userID': 1,
'verbID': 26,
'objectID':1
};
$.ajax({
type: "GET",
cache: false,
dataType: "json",
url: "/Admin/NewStatement",
data: postData,
success: function (data) {
var json = data;
alert("THIS IS MY JSON" + json);
//tincan.sendStatement(json);
},
error: function (error) {
alert("An Error has occurred during the Creation of this xAPI Statement");
alert(error);
}
});
我在Admin / NewStatement
有以下方法public string NewStatement(int userID, int verbID, int objectID)
{
string result;
result = avm.AddStatement(userID, verbID, objectID);
return result;
}
avm.AddStatement指的是我的ViewModel代码:
public string AddStatement(int userID, int verbID, int objectID)
{
Actor actor = actorRepository.Get(a => a.UserID == userID).FirstOrDefault();
Verb verb = verbRepository.Get(v => v.VerbID == verbID).FirstOrDefault();
StatementObject statementObject = statementObjectRepository.Get(o => o.StatementObjectID == objectID).FirstOrDefault();
Statement newStatement = new Statement();
newStatement.id = System.Guid.NewGuid();
newStatement.ActorID = actor.ActorID;
newStatement.VerbID = verb.VerbID;
newStatement.StatementObjectID = statementObject.StatementObjectID;
this.statementRepository.Add(newStatement);
this.statementRepository.SaveChanges();
JsonSerializerSettings jss = new JsonSerializerSettings();
jss.ObjectCreationHandling = ObjectCreationHandling.Auto;
var json = JsonConvert.SerializeObject(newStatement);
return json.ToString();
}