Skip to main content
WolfShade
Legend
August 17, 2017
Question

ColdFusion JSON parsing failure: Expected '"' at character 2: '&'

  • August 17, 2017
  • 1 reply
  • 4491 views

Hello, all,

I'm trying to convert a project so that the components folder is outside of the webroot.  For the most part, this has been a smooth transition.

Until (dun dun dunnnnnnnn) I get to the parts where I am using AJaX to submit forms.  When the component was in the webroot, it was very simple, very straightforward.  Now that the components exist outside the webroot, cfajaxproxy is giving me fits.

If all I'm submitting is a single form field value, it works.  If I'm submitting an entire form using jQuery.serializeArray(), suddenly there's a problem.

postData = $('#'+formID).serializeArray();

thisComponent = new ERC(); //Component is in F:\webdocs\_com\public\ERC.cfc and components are mapped in application.cfc

thisComponent.setHTTPmethod('POST');

thisComponent.setCallbackHandler(displayResult);

thisComponent.setErrorHandler(displayFail);

thisComponent.dtsSurvey(postData); // Submit the form to the function "dtsSurvey" in ERC.cfc

This results in the error message mentioned in the subject:  JSON parsing failure: Expected '"' at character 2: '&'

The reason why is because ColdFusion sees: {"form":[{"name"...  (The JSON " are being converted to ASCII.)

How can I fix this?  I've Googled for it, and I'm not finding a solution.

V/r,

^ _ ^

    This topic has been closed for replies.

    1 reply

    Inspiring
    August 17, 2017

    Are we able to see roughly how dtsSurvey function works.

    Assuming the json is correct passing it to that, then something that side maybe changing it.

    WolfShade
    WolfShadeAuthor
    Legend
    August 17, 2017

    Hi, haxtbh,

    The JSON isn't even making it to the function.  In the very beginning of the function, I placed a <CFDUMP var="#form#" /><cfabort> (the function doesn't 'return' anything, it outputs.)  I'm not getting that dump, at all.  The error is being triggered in the cfajax.js because CF can't correctly parse it.  I think CFAJAXPROXY is replacing the quotes, but can't be sure - something is.

    But my onError() is triggering the error email before my CFTRY/CFCATCH can get it, so I'm not being given a file or line number for the error.

    F12 in FireFox Developer Edition is showing that the error is in cfajax.js on multiple lines.

    V/r,

    ^ _ ^

    WolfShade
    WolfShadeAuthor
    Legend
    August 28, 2017

    WolfShade  wrote

      And canonicalize() should take care of it, but apparently it isn't.

    Then, chances are, the good man had used xmlFormat().


    Okay.  I'm not sure where to go, now.

    I've got the form submitting, but what the function sees is not the form scope, but an array.  Okay, no big deal, I can iterate the array and manually build the form scope.

    But what is confusing, now, is that something is STILL breaking cfajax.js; and that, in turn, is canceling all the JavaScript that is supposed to happen after the submit (ie, display the results, change the captcha, etc.)

    ???

    F12 in FireFox says only that the error is in /CFIDE/scripts/ajax/package/cfajax.js on six different lines.  Things like "this.decode", "$X.processResponse", "$X.callback", and whatnot.  But no actual indication of what is going wrong.

    **headdesk**  **headdesk**  **headdesk**  **headdesk**  **headdesk**  **headdesk** 

    V/r,

    ^ _ ^