Link to home
Start Free TrialLog in
Avatar of 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: 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;
      var testCanvas = document.getElementById("imageView");  
      var canvasData = testCanvas.toDataURL("image/png");
      var ajax = new XMLHttpRequest();
      //alert ('' + document.form.ptname.value.replace(/ /g,"_"));"POST",'' + document.form.ptname.value.replace(/ /g,"_"),false);
      ajax.setRequestHeader('Content-Type', 'canvas/upload');
      //ajax.setRequestHeader('Content-Type', 'application/upload');
            if (ajax.readyState == 4)
                  // Write out the filename.
                  //document.getElementById("debugFilenameConsole").innerHTML="Saved as<br><a target='_blank' href='"+ajax.responseText+"'>"+ajax.responseText+"</a><br>Reload this page to generate new image or click the filename to open the image file.";

Any help would be appreciated.

Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

You for sure need to remove the "v" at the end of this line in PainDiagram.js

canvas.addEventListener('touchcancel', ev_canvas, false);v <<<<<

I cannot test until you fix the two errors I have found

Error 2

return checkdate(document.form.dob.value);

Open in new window

is sending a string instead of field. Change to 

return checkdate(document.form.dob);

Open in new window

to match

if (returnval==true)

Open in new window

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.")
      returnval = false
  if (returnval == true); // here we select the field
  return returnval

Open in new window

Lastly I think you meant 

if (!returnval);

Open in new window

Avatar of thenelson



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.
Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.


No problem. You still will need my change to make the code not give errors. There is no select method of a string.

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 ;)

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?

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.

I am not getting any errors.

I cannot verify on my mobile. No big deal.