thenelson
asked on
Problem with Ajax post
I have a HTML5/js web page that was working fine and stopped working a short time ago. I have placed this web page temporally at: https://www.barnwellmd.com/temp/test.html so I can delete it after I close this question (it saves files on my server and sends me an email).
The problem is when a user clicks on "Send to Dr. Office" a popup shows "<head><title>Not Acceptable!</title></head> <body><h1> Not Acceptable!</h1><p>An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.</p></body></ html>" and nothing is sent.
That button calls the sendCanvas() function:
function sendCanvas()
{
if (checkFields()) return;
clearGray();
createPrint();
var testCanvas = document.getElementById("i mageView") ;
var canvasData = testCanvas.toDataURL("imag e/png");
//alert(canvasData);
var ajax = new XMLHttpRequest();
//alert ('https://www.barnwellmd.com/Uploadroutines/uploadbase64.php?name=' + document.form.ptname.value .replace(/ /g,"_"));
ajax.open("POST",'https://www.barnwellmd.com/Uploadroutines/uploadbase64.php?name=' + document.form.ptname.value .replace(/ /g,"_"),false);
//ajax.open("POST",'https://www.barnwellmd.com/Uploadroutines/uploadbase64.php',true);
ajax.setRequestHeader('Con tent-Type' , 'canvas/upload');
//ajax.setRequestHeader('C ontent-Typ e', 'application/upload');
ajax.onreadystatechange=fu nction()
{
if (ajax.readyState == 4)
{
alert(ajax.responseText);
// Write out the filename.
//document.getElementById( "debugFile nameConsol e").innerH TML="Saved as<br><a target='_blank' href='"+ajax.responseText+ "'>"+ajax. responseTe xt+"</a><b r>Reload this page to generate new image or click the filename to open the image file.";
}
}
ajax.send(canvasData);
}
Any help would be appreciated.
Thanks.
The problem is when a user clicks on "Send to Dr. Office" a popup shows "<head><title>Not Acceptable!</title></head>
That button calls the sendCanvas() function:
function sendCanvas()
{
if (checkFields()) return;
clearGray();
createPrint();
var testCanvas = document.getElementById("i
var canvasData = testCanvas.toDataURL("imag
//alert(canvasData);
var ajax = new XMLHttpRequest();
//alert ('https://www.barnwellmd.com/Uploadroutines/uploadbase64.php?name=' + document.form.ptname.value
ajax.open("POST",'https://www.barnwellmd.com/Uploadroutines/uploadbase64.php?name=' + document.form.ptname.value
//ajax.open("POST",'https://www.barnwellmd.com/Uploadroutines/uploadbase64.php',true);
ajax.setRequestHeader('Con
//ajax.setRequestHeader('C
ajax.onreadystatechange=fu
{
if (ajax.readyState == 4)
{
alert(ajax.responseText);
// Write out the filename.
//document.getElementById(
}
}
ajax.send(canvasData);
}
Any help would be appreciated.
Thanks.
I cannot test until you fix the two errors I have found
Error 2
return checkdate(document.form.dob.value);
is sending a string instead of field. Change to
return checkdate(document.form.dob);
to match
if (returnval==true) input.select()
so you can change
function checkdate(inputField) { // change to field
var input = inputField.value;
var validformat = /^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
var returnval = true
if (!validformat.test(input))
alert("Invalid Date Format. Format: (mm/dd/yyyy) \nPlease correct and submit again.")
else { //Detailed check for valid date ranges
var monthfield = input.split("/")[0]
var dayfield = input.split("/")[1]
var yearfield = input.split("/")[2]
var dayobj = new Date(yearfield, monthfield - 1, dayfield)
if ((dayobj.getMonth() + 1 != monthfield) || (dayobj.getDate() != dayfield) || (dayobj.getFullYear() != yearfield))
alert("Invalid Day, Month, or Year range detected. \nPlease correct and submit again.")
else
returnval = false
}
if (returnval == true) inputField.select(); // here we select the field
return returnval
}
Lastly I think you meant
if (!returnval) inputField.select();
ASKER
Michel,
Nice catch on the v on the end of the line. - thanks!
I made the changes you suggested for checkdate but got:
"Invalid Date Format. Format: (mm/dd/yyyy)
Please correct and submit again."
It has been years since I wrote that code but I bet I used a string so I can check the format of the date input which should be mm/dd/yyyy.
Thanks for your input.
Nice catch on the v on the end of the line. - thanks!
I made the changes you suggested for checkdate but got:
"Invalid Date Format. Format: (mm/dd/yyyy)
Please correct and submit again."
It has been years since I wrote that code but I bet I used a string so I can check the format of the date input which should be mm/dd/yyyy.
Thanks for your input.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I contacted hostgator, about "The server error is not related to the client side code". Gave them the Wordpress page you provided. They acknowledged that the problem is on their side but could not fully resolve it. They escalated the problem and will get back to me. I'm going to hold off with your other suggestions until after they solve the server side problems. I'll let you know.
Thanks!!
Thanks!!
No problem. You still will need my change to make the code not give errors. There is no select method of a string.
ASKER
Strange that the code has worked fine for 8 years and the checkdate function works fine now with the string. But when Hostgator gets done at their end, I will work with you on what you're suggesting.
It is working if you ignore the console error and that the error field is not selected ;)
ASKER
Hostgator got the server problem fixed.
The page is working fine now - why do I need to change the code if it is working fine?
The page is working fine now - why do I need to change the code if it is working fine?
It’s likely still giving a console error. If you do not care you do not have to do anything - I would fix it had it been my site - anyway enjoy.
ASKER
I am not getting any errors.
I cannot verify on my mobile. No big deal.
You for sure need to remove the "v" at the end of this line in PainDiagram.js
canvas.addEventListener('touchcancel', ev_canvas, false);v <<<<<