jQuery ajax seems to alter SVG data sent to coldfusion server

ⅰ亾dé卋堺 提交于 2019-11-29 17:07:07

I haven't used the framework you've used, however should the line where you set the svg variable use the getSVG query?

<cfset svg = getSVG.svg>

Couple of things:

  1. I assume your storing the SVG in a UTF-8 compatible field?
  2. Can you confirm that the SVG is correct after grabbing it from the DOM and before posting it?
  3. In your ColdFusion Administrator, go to your datasource settings and click 'Show Advanced Settings'. Make sure the box labeled 'Enable High ASCII characters and Unicode for data sources configured for non-Latin characters' is checked.

I've continued working on and refining this issue and have narrowed the problem down. I have posted Well this doesn't really answer my question (not being a $.ajax() fix) but it does fix the issue... Instead of using jQuery ajax() to pass the svg code I created a css-hidden div with a form and a iFrame in it. I use jQuery code to load the ID and svg into inputs in the hidden div. Then I use jQuery to submit that form into the iFrame. It works very smoothly in the background. Later when I query the SVG from the table, it doesn't throw a utf-8 error.

Sharing the code for whoever it might help:

<div id="zeroDiv" style="display:none">
  <form id="svgForm" action="saveSVG.cfm" method="post" target="zeroFrame" accept-charset="utf-8">
    <input name="ordID" id="ordID" type="hidden" value="" />
    <input name="svgCode" id="svgCode" type="hidden" value="" />
  </form>
  <iframe id="zeroFrame" name="zeroFrame" src="" style="width:0;height:0;border:0px solid #fff; display:none"></iframe>
</div>

This is the javascript/jQuery which calls and submits it:

var lclSVG = $('#holderDiv')[0].innerHTML;
lclSVG = lclSVG.replace(/&quot;/g,"");
$('#ordID').val(ordID);
$('#svgCode').val(lclSVG);
$('#svgForm').submit();

This is the CF code on the saveSVG.cfm page. It could be any server side tech...

<cfif isDefined("form.ordID") AND Val(form.ordID) AND isDefined("form.svgCode") AND Len(Trim(form.svgCode))>
  <CFQUERY NAME="saveSVG">
    UPDATE sketch
    SET sketch_svg = '#form.svgCode#' 
    WHERE  ordID = #Val(form.ordID)#
  </CFQUERY>
</cfif>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!