• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Using ajaxproxy CFC any error (even handled) causes parsejson error

Explorer ,
Dec 14, 2012 Dec 14, 2012

Copy link to clipboard

Copied

I'm trying to use a CFC in an ajaxproxy.  If I make a simple function it works fine, but as soon as I start getting into more complex scenarios, some of which may need to have a caught error for connection failures and such, instead of returning the error it just returns a parsejson syntax error in the javascript.  I've even tried using a try catch and returning a structure with the error details but that doesn't work either, still gives the parsejson error.  I've tested and confirmed without any actual error the struct returns fine with false error data in it, but as soon as it's a real error it doesn't work.

This makes using a ajaxproxy nearly useless if you can't capture and handle errors in it.  Surely I'm simply doing something wrong?

This is on a developer edition, Coldfusion 9, Apache 2.2, Windows 7 Host.

TOPICS
Advanced techniques

Views

1.3K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 14, 2012 Dec 14, 2012

Copy link to clipboard

Copied

Capture the JSON output and paste it into a JSON validator like this one: http://jsonformatter.curiousconcept.com/

In my experience, CF over escapes some of the text data, particularly single quotes - JSStringFormat puts a backslash before single quotes which is invalid JSON. I create a JSONStringFormat function myself and simply do a replace(jsonStringFormat(someString),"\'|,"'","ALL") and this fixes it. I know there are probably more efficient way, but this works and I would not be surprised if there are other invalid format cases.

BTW, I have already submitted a bug report on this one.

Hope this helps.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 14, 2012 Dec 14, 2012

Copy link to clipboard

Copied

Sorry, maybe I wasn't clear.  There is NO json output to capture in this instance.  My return type in the CFC is a structure.  The only thing that should be returning is that structure.  However it seems if there is any error something else is being output even though my function output is set to no.  And the errors are fully handled, so nothing should be written to HTML at all for this.  When it happens though I get no return data at all, simply that parsejson error.  I don't even see a way to find out what it is even trying to parse in order to look at that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 14, 2012 Dec 14, 2012

Copy link to clipboard

Copied

Whether you know it or not, JSON is being used. To pass a structure, most commonly the structure is convertted into a JSON, XML, or WDDX format. Based on the error you are seeing, JSON is being used. This is one of the reasons I don't use the built in ajax/cfc functionality that CF provides and instead write my own using jquery and my own JSON data provider logic -- this way I know the in's and out's in fine detail.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 14, 2012 Dec 14, 2012

Copy link to clipboard

Copied

Is there a way to see what is being parsed prior to the parsing and the resulting error?  I don't see any way to do it personally.  So it leads me back to my original problem of why is it even happening in the first place.  The structure returns fine as long as there is no real error, but even if I use <cfthrow> inside a <cftry>, it gets the parsejson error.  Even though the error is handled through a <cfcatch>.  It makes no sense, I could understand if the error wasn't handled then the error debug data output that I have setup could cause the parsejson error, but with a handled error there should be no output at all.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Dec 14, 2012 Dec 14, 2012

Copy link to clipboard

Copied

RE: Is there a way to see what is being parsed prior to the parsing and the resulting error?

Yep, use Firefox and install the Firebug add-on. It's a priceless tool and it's free.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 14, 2012 Dec 14, 2012

Copy link to clipboard

Copied

@Steven6282

Could you please illustrate with some code?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 10, 2013 Jan 10, 2013

Copy link to clipboard

Copied

LATEST

most of the time i'm using securejson param in the cfc function declaration, like:

<cffunction name="someName" output="false" access="remote" securejson="true">

then i usually do the error trapping inside the function, like:

<cftry>

     ... do something...

   <cfcatch>

         <cfreturn "do something failed"><cfabort>

   </cfcatch>

</cftry>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation