0

我正在使用“accept-charset='utf-8'”将 SVG 数据发布到操作页面。在操作页面上,我将该数据插入到表中。稍后,在另一个页面中,我从表中查询该数据并通过 Batik 运行它以将其转码为 PNG 文件。它运作良好。

<form action="test_action.cfm" method="post" target="_blank" accept-charset="utf-8">

如果我从表单标记中删除了 accept-charset="utf-8" ,那么稍后(在转码页面上)我会收到“3 字节 UTF-8 序列的无效字节 2”错误(尝试转码时)。

此外,我尝试使用 jQuery 的 .ajax() 尝试在后台处理操作页面的每一种方式都会遇到相同的错误。使用 'accept-charset="utf-8"' 使一切正常。

尝试使用 $.ajax() 将 SVG 发送到后台的操作页面:

var lclSVG = $('#myDiv')[0].innerHTML;
$.ajax({
  url: "myAction.cfm",
  type: "POST",
  data: ({myInfo: lclSVG}),
});

有没有办法通过 $.ajax() 发布这些数据,同时强制 .ajax() 执行类似 'accept-charset="utf-8"' 的操作?

4

1 回答 1

0

According to the JQuery ajax() docs, the default already is UTF-8. But maybe try to foce the setting anyhow, as per those docs, with the contentType option. You might also want to look at the processData option, as it specifically mentions XML handling.

I agree with your analysis, but have you verified that the corruption is occurring during the upload process, or some quirk to do with your transcoding (more details against this question): perhaps things are running slightly different between your normal file upload and your AJAX upload?

To eliminate this, rather than processing right through to transcoding, maybe just write the data to an SVG and test it before trying the transcoding (just as a troubleshooting step, I mean).

You might get some more hints as to what's going on by using Firebug to look at the request to the server that sends the file: compare the two approaches and look for differences.

Not an explicit answer, I'm afraid, but perhaps some stuff to look at.

于 2012-11-04T11:07:16.590 回答