I have the following javascript:
function foo()
{
var someObject = $("#someTextbox").val();
var contentType = 'application/x-www-form-urlencoded; charset=UTF-8;';
AjaxRequest(someObject, 'html', 'post', '/ErrorCheck/SaveToFile', contentType, function(response)
{
//stuff
}, function(error)
{ });
}
function AjaxRequest(data, dataType, type, url, contentType, success, error, args)
{
try
{
var useFD = false;
var form = new FormData();
if (type.toUpperCase() == 'POST')
{
if (contentType && contentType.indexOf('application/x-www-form-urlencoded; charset=UTF-8;') === 0)
{
form.append("MyData", JSON.stringify(data));
url = antiForgeryToken.add(url);
useFD = true;
}
}
$.ajax(
{
processData: useFD ? false : true,
mimeType: useFD ? "multipart/form-data" : "",
async: args.async,
cache: args.cache ? true : false,
data: useFD ? form : data,
dataType: dataType,
type: type,
url: url,
contentType: contentType,
traditional: true,
headers:
{
'__RequestVerificationToken': antiForgeryToken.token() != false ? antiForgeryToken.token().val() : '',
'__loginUserId': $('#hidLOGINUSERID').val()
},
beforeSend: function(request)
{ },
success: function(data, textStatus, XMLHttpRequest)
{
try
{
success(data, textStatus, XMLHttpRequest);
}
catch (e)
{}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {},
complete: function(XMLHttpRequest) {}
});
}
catch (err)
{}
}
In the above scenario, useFD
is true
.
Then in my ErrorCheck
controller's SaveToFile
method, I have the following:
public void SaveToFile()
{
try
{
if (Request.Form.Count > 0)
{
//do stuff
}
}
catch (Exception ex)
{
ElmahLogUtility.ErrorException(ex);
}
}
However, Request.Form.Count
is always zero. I got this solution from a question I asked a few months ago here. I accepted the solution there back in October and I know this code was working, however it didn't get to a testing environment until just recently and it is no longer working, not even in my local environment.
What am I doing incorrectly?