function SubmitAPI(apiurl_value, stagecompleted_value, successmsg_value, emailsubject_value, emailaddress_value, emaildestination_value) {
var x = $('#formdiv *').serializeArray();
var data = {};
var apiurl = apiurl_value;
var stagecompleted = stagecompleted_value;
var successmsg = successmsg_value;
var emailsubject = emailsubject_value;
$.each(x, function (i, field) {
data[field.name] = field.value;
});
var jsondata = JSON.stringify(data);
$.ajax({
url: apiurl,
type: "POST",
data: { 'message': jsondata.replace(/\"/g, "'"), 'email': emailaddress_value, 'emailsubject': emailsubject, 'emaildestination': emaildestination_value },
dataType: 'json',
success: function (data) {
if (data.stage === stagecompleted) {
alert(successmsg);
document.location.reload();
}
},
error: function (msg) { alert(msg); }
});
return false;
}
[HttpPost]
[ValidateInput(false)]
public JsonResult ReceiveJson(string message, string email, string emailsubject, string emaildestination)
{
#region str object
string stageCompletedLabel = System.Configuration.ConfigurationManager.AppSettings["StageCompletedLabel"];
string emailReceiver = emaildestination;
Domain.Contact c = new Domain.Contact();
string guidKey = Guid.NewGuid().ToString();
string fromEmail = email;
var responseStr = JsonConvert.DeserializeObject<Dictionary<string, string>>(message);
string dataList = "";
string breakInHtml = "<br>";
foreach (var kv in responseStr)
{
#region get data
dataList = dataList + (kv.Key.Replace("_", " ") + ": " + kv.Value + breakInHtml);
#endregion
}
#region email
DomainHelper.SMTP.SendEmailWithOutAttachment(emailsubject, dataList, fromEmail, emailReceiver);
#endregion
#endregion
c.stage = stageCompletedLabel;
return Json(c, JsonRequestBehavior.AllowGet);
}
data: {
message: JSON.stringify( $('#formId').serialize() ),
email,
emailsubject,
emaildestination
},
If that doesn't work, just debug your code behind and see what's being received in the message variable
Hi,
If you're trying to send the form contents through your AJAX request, you can just use the serialize() method on the form:
Open in new window