MVC Code
[HttpPost]
public ActionResult GetOpenDripCampaingns(Campaign cam)
{
var result = string.Empty;
try
{
var postReq = (HttpWebRequest)WebRequest.Create(ConfigurationManager.AppSettings["OpenDripCampaigns"].ToString());
postReq.Method = "GET";
postReq.ContentType = "application/x-www-form-urlencoded";
postReq.Headers.Add("Authorization", cam.Authorization.Replace('"', ' ').Trim());
var httpWebReponse = (HttpWebResponse)postReq.GetResponse();
StreamReader responseReader = new StreamReader(httpWebReponse.GetResponseStream());
result = responseReader.ReadToEnd();
httpWebReponse.Close();
responseReader.Close();
}
catch (Exception ex)
{
throw ex;
}
return Json(result, JsonRequestBehavior.AllowGet);
}
JQuery Code
$('#Dripsubmit').click(function ()
{
var form = $("form");
form.validate();
if (form.valid() && !window.isSubmitted)
{
window.isSubmitted = true;
var cam = {
Authorization: $("#Authorization").val()
};
$.ajax({
url: "/OpenDripCampaign/GetOpenDripCampaingns",
type: "POST",
contentType: "application/json;charset=utf-8",
data: JSON.stringify(cam),
dataType: 'json',
timeout: 1200000,
async: true,
success: function (data)
{
var myresult = $.parseJSON(data);
var finalData = JSON.parse(myresult);
$.each(finalData, function (i)
{
$("#tbldetails").append("
" + finalData[i].campaign_Id + " | " + finalData[i].CampaignName + " | " + finalData[i].campaignScheduledDate + " |
");
});
},
error: function(err)
{
window.isSubmitted = false;
displaySwalMessageWithButton("Please resolve all errors to proceed further.", "Warning");
console.log(err);
}
});
}
});