Javascript \ 将双字节日文 space 更改为英文 space

Javascript \ change double byte Japanese space to an English space

我有一个文本框可以输入文本,但是服务器不能处理双字节space。 我想在发送前将其转换为常规 space。

尝试过

var content = "よろしいでしょう キャンセル"
content = content.replace(" ", " ");

但现在 IDE 尖叫说不能那样保存它。 有标准的方法吗?

来自 Fiddler 的请求 header:

POST /blablabla/SearchTerm HTTP/1.1
Host: localhost
Connection: keep-alive
Content-Length: 290
Accept: application/json
Origin: http://localhost
X-Requested-With: XMLHttpRequest
Accept-Language: en-US
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36
Content-Type: application/json
Referer: http://localhost/blablabla
Accept-Encoding: gzip, deflate

并且请求本身来自提琴手:

{...."content":"\u3088\u308d\u3057\u3044\u3067\u3057\u3087\u3046\u3000\u30ad\u30e3\u30f3\u30bb\u30eb"....}

和来自 javascript

的 Ajax 电话
  // Invoke request to server and register to the success and failure events
            Ext.Ajax.request({
                url: '/blablabla/SearchTerm',
                method: "POST",
                headers: this.header || {
                    "Content-Type": "application/json",
                    "Accept": "application/json"
                },
                jsonData: {                  
                    content: content,                   
                },
                timeout: this.configuration.getAjaxRequestTimeout(),
                success: searchCompletedSuccessDelegate,
                failure: searchCompletedFailureDelegate
            });

我猜你的 IDE 不支持 space \u3000 的编码,所以你可以使用带有 \u 转义的 unicode 符号(不知道真实姓名):

//will work in any case
var content = "\u3088\u308d\u3057\u3044\u3067\u3057\u3087\u3046\u3000\u30ad\u30e3\u30f3\u30bb\u30eb";
content.replace("\u3000"," ")

我不知道 VS,但一些 IDE 可以将文件配置为编码为 UTF-8 以避免该问题。