It works fine in local Chrome, IE and Edge if running in Visual Studio but does not work when deployed on local server IIS 10.
The Alert "ERROR!" does come up
{"Message":"Invalid web service call, missing value for parameter: \u0027name\u0027.","StackTrace":" at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 parameters)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)","ExceptionType":"System.InvalidOperationException"}
var image = document.getElementById("cnv").toDataURL("image/png");
image = image.replace('data:image/png;base64,', '');
$.ajax({
type: 'POST',
url: "Default.aspx/MyWebMethod",
data: '{ "imageData" : "' + image + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
alert('Image saved successfully !');
},
error: function (msg) {
alert('ERROR!');
}
function SetSession()
{
var name1 = document.getElementById("<%=txtDate.ClientID%>").value;
var name2 = document.getElementById("<%=txtEntityID.ClientID%>").value;
var name3 = document.getElementById("<%=txtEmail.ClientID%>").value;
var name4 = document.getElementById("<%=txtSSN.ClientID%>").value;
var name5 = document.getElementById("<%=txtAddressLine1.ClientID%>").value;
var name6 = document.getElementById("<%=txtAddressLine2.ClientID%>").value;
var name7 = document.getElementById("<%=txtHeadName.ClientID%>").value;
var name8 = document.getElementById("<%=txtLandlordName.ClientID%>").value;
var name9 = document.getElementById("<%=txtLandlordPhone.ClientID%>").value;
var name10 = document.getElementById("<%=txtPhone.ClientID%>").value;
var ctx = document.getElementById('cnv').getContext('2d');
var name11 = ctx;
var img = new Image();
var obj = null;
var image = document.getElementById("cnv").toDataURL("image/png");
image = image.replace('data:image/png;base64,', '');
$.ajax({
type: 'POST',
url: "Default.aspx/SetSession",
data: '{ "imageData" : "' + image + '" }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function(msg) {
alert('Image saved successfully !');
},
error: function(msg) {
alert(msg.responseText);
}
});
// ****** Error is on the following line
var name = name1 + ";" + name2 + ";" + name3 + ";" + name4 + ";" + name5 + ";" + name6 + ";" + name7 + ";" + name8 + ";" + name9 + ";" + name10 + ";" + image;
var request;
if (window.XMLHttpRequest)
{
//New browsers.
request = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
//Old IE Browsers.
request = new ActiveXObject("Microsoft.XMLHTTP");
}
if (request != null)
{
var url = "Default.aspx/SetSession";
request.open("POST", url, false);
var params = "{name: '" + name + "'}"; // + "," + "{name: '" + name2 + "'}";
request.setRequestHeader("Content-Type", "application/json");
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200)
{
alert(JSON.parse(request.responseText).d);
}
};
request.send(params);
}
}
WebMethod
[System.Web.Services.WebMethod(EnableSession = true)]
public static string SetSession(string name)
{
HttpContext.Current.Session["Name"] = name;
string[] values = name.Split(';');
string str = name;
//var result = from s in str.ToLowerInvariant().Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
var result = from s in str.ToLowerInvariant().Split(new char[] { ';' })
select s;
string sMoQ = values[10];
string imageData = values[10];
string strUploadDestinationK = ConfigurationManager.AppSettings["UploadDestinationK"].ToString();
string fileNameWitPath = @strUploadDestinationK + DateTime.Now.ToString().Replace("/", "-").Replace(" ", "- ").Replace(":", "") + ".png";
using (FileStream fs = new FileStream(fileNameWitPath, FileMode.Create))
{
using (BinaryWriter bw = new BinaryWriter(fs))
{
byte[] data = Convert.FromBase64String(sMoQ);
bw.Write(data);
bw.Close();
}
}
string[] stringarr;
stringarr = values;
string str1 = values[0];
string str2 = values[1];
string sDate = values[0];
string sEntityID = values[1];
string sID = values[1];
string sEmail = values[2];
string sSSN = values[3];
string sAddressLine1 = values[4];
string sAddressLine2 = values[5];
string sHeadName = values[6];
//string sHeadSignature = values[0];
string sLandlordName = values[7];
string sLanllordPhone = values[8];
string sPhone = values[9];
string sLandlordSignature = "_____________________________"; // values[10];
string sHeadSignature = "_____________________________"; // values[11];
string sTemp = GetImageSession();
Document document = new Document(PageSize.LETTER, 100f, 100f, 10f, 10f);
iTextSharp.text.Font NormalFont = FontFactory.GetFont("Arial", 12, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);
using (System.IO.MemoryStream memoryStream = new System.IO.MemoryStream())
{
PdfWriter writer = PdfWriter.GetInstance(document, memoryStream);
Phrase phrase = null;
PdfPCell cell = null;
PdfPTable table = null;
BaseColor color = null;
document.Open();
table = new PdfPTable(2);
table.TotalWidth = 550f;
table.LockedWidth = true;
table.SetWidths(new float[] { .3f, 2.3f });
cell = ImageCell("~/images/FormLogo2.png", 60f, PdfPCell.ALIGN_CENTER);
table.AddCell(cell);
}
}