I built a website using ASP.NET MVC and Knockoutjs. This is hosted on IIS on Windows Sever 2012. There is another web application where I use ajax to POST and that application does not give any errors. The Submit button on the website is binded using the click bind to this function. This works when I run it in Debug mode on the localhost.
self.SubmitEvaluation = function () {
reqUrl = "/Home/SubmitEvaluation";
$.ajax({
type: "POST",
url: reqUrl,
data: JSON.stringify({ evaluation: ko.toJSON(self) }),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
if (response == 1) {
self.EvalComplete(true);
} else {
self.EvalComplete(false);
alert("Submission Failed. Please resubmit!!!")
}
},
error: function (jqXHR, exception) {
if (jqXHR.status === 0) {
alert('Not connect.\n Verify Network.');
} else if (jqXHR.status == 404) {
alert('Requested page not found. [404]');
} else if (jqXHR.status == 500) {
alert('Internal Server Error [500].'+exception.toString());
} else if (exception === 'parsererror') {
alert('Requested JSON parse failed.');
} else if (exception === 'timeout') {
alert('Time out error.');
} else if (exception === 'abort') {
alert('Ajax request aborted.');
} else {
alert('Uncaught Error.\n' + jqXHR.responseText);
}
}
});
In the home controller I have these two web methods.
[HttpGet]
public string Test()
{
Logger.Logger.WriteLog("Test", "Inside Test");
TestModel product = new TestModel();
product.Name = "Apple";
product.Price = "3.99M";
return JsonConvert.SerializeObject(product);
}
[HttpPost]
public int SubmitEvaluation(string evaluation)
{
Logger.Logger.WriteLog("Submitevaluation", "Inside SubmitEvaluation");
int result = -1;
try
{
EvaluationModel eval = JsonConvert.DeserializeObject<EvaluationModel>(evaluation);
MySqlConnection conn = new MySqlConnection(connStr);
conn.Open();
string sql = "INSERT INTO xyz table blah blah blah";
MySqlCommand cmd = new MySqlCommand(sql, conn);
result = cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
Logger.WriteLog("Submitevaluation", ex.ToString());
}
return result;
}
I receive Internal Sever Error 500 from the Ajax request when I click on the Submit button.
But if I do this http://xxx.xxx.xxx.xxx/Home/Test I get the json result back {"Name":"Apple","Price":"3.99M"}.
Response header from Fiddler
HTTP/1.1 500 Internal Server Error Cache-Control: private Content-Type: text/html; charset=utf-8 Server: Microsoft-IIS/8.0 X-AspNetMvc-Version: 4.0 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Thu, 09 Jan 2014 16:22:16 GMT Content-Length: 276
After turning on customer errors and detailed error message I am receiving this message.
Could not load file or assembly 'MySql.Data, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' or one of its dependencies. The system cannot find the file specified
I downloaded the Mysql connector from http://dev.mysql.com/downloads/connector/net/ and I added the assembly by right clicking on References > Extensions and selecting the 4.0 version. I also tried the 4.5.