Data types may be different between ColdFusion and jQuery.
May 18
by Gregory Alexander Ajax and ColdFusion

I developed code that gets and sets theme settings from a .ini file. I am using getProfileString and setProfile string to set the various theme properties in a ColdFusion component on the server side. Depending upon the approach that I use, the datatypes that are being returned to the client are different. For example, if I invoke the function from a .cfm page, the values that I am getting are stored in strings, and are being returned as either a 'yes' or 'no'. However, if I invoke the same function from ajax, the value is being returned as a boolean value, i.e. true or false. The component and the method are the same, but the evaluation of the return value is different between ColdFusion and jQuery. Be aware that if you don't declare and set the datatype of the structure elements independently; the datatypes can be interpreted differently depending upon where they are being evaluated.
This entry was posted on May 18, 2019 at 5:13 PM and has received 328 views.
JSON Parse Error in jQuery when using a Coldfusion function inside a .cfm page.
May 18
by Gregory Alexander Ajax and ColdFusion

Late at night, I put a function inside a .cfm template and tried to consume it from Ajax, but I received a json parse error that was displayed in Chrome's console when trying to invoke a function within a .cfm page. I had forgot that ajax functions should not be consuming a .cfm page, and placed the exact same function within a component with a .cfc extension, and the issue went away. When a function is within a component with the access remote argument, ColdFusion will autogenerate a web services stub, but it does not do this within a .cfm page. If you receive a json parse error using logic that is known to create a valid json object within a .cfm page, try putting the same code in a .cfc component and consume it there. It may solve this parse error for you as well. The code below has a 'proxyControllerUrl' variable that was initially using a template with a .cfm extension, and it failed. However, when I put the same function within a .cfc extension, it worked.
ColdFISH is developed by Jason Delmore. Source code and license information available at coldfish.riaforge.org function getAllThemeSettingsFromIniStore(themeId){ // Get all of the theme properties stored in the ini configuration file. $.ajax({ type: "get", url: "<cfoutput>#application.proxyControllerUrl#?</cfoutput>method=getAllThemeSettingsFromIniStore",//Works with a .cfc component, fails when the method is inside a .cfm template. data: { // method and the arguments themeId: themeId }, dataType: "json", cache: false, success: function (data){ // Pass the data to the getAllThemeSettingsResult function. getAllThemeSettingsResult(data); }, error: function(xhr, textStatus, error){ console.log(xhr.statusText);//Parse error shows up here when inside a .cfm template. console.log(textStatus); console.log(error); } }); }//... function 1function getAllThemeSettingsFromIniStore(themeId){ 2 3 // Get all of the theme properties stored in the ini configuration file. 4 $.ajax({ 5 type: "get", 6 url: "<cfoutput>#application.proxyControllerUrl#?</cfoutput>method=getAllThemeSettingsFromIniStore",//Works with a .cfc component, fails when the method is inside a .cfm template. 7 data: { // method and the arguments 8 themeId: themeId 9 }, 10 dataType: "json", 11 cache: false, 12 success: function (data){ 13 // Pass the data to the getAllThemeSettingsResult function. 14 getAllThemeSettingsResult(data); 15 }, 16 error: function(xhr, textStatus, error){ 17 console.log(xhr.statusText);//Parse error shows up here when inside a .cfm template. 18 console.log(textStatus); 19 console.log(error); 20 } 21 }); 22}//... function |
This entry was posted on May 18, 2019 at 2:26 AM and has received 521 views.
Download Galaxie Blog
Subscribe
Tags
Recent Posts
Recent Comments
Archives
Monthly Archives
CFBloggers Feed
_UNKNOWNTRANSLATION_ |