我目前正在解决标题中提到的问题,而且我在某种程度上找不到用双反斜杠正确替换反向的方法,这样我就可以正确地将字符串作为参数提供给web服务。 让我告诉你我的尝试。 其中一些确实适用于其他人,但不适合我...我正在使用FF18.0.1进行测试
WSParameters.replace(/\\/g, "\\\\\\\\"); WSParameters.replace("\\", "\\\\\\\\"); WSParameters.replace(/\\/g, "\\\\"); WSParameters.replace(/\\/g, "\\"); WSParameters.replace(/\\/g, "\"); WSParameters.replace("\\", "\\\\");非常感谢提前
编辑:我应该提到它以某种方式解析为JSON和firebug我看到源字符串中的反斜杠,但不是在JSON视图中。 也许有另一种方式? 但不知何故,它已经失败了更换反斜杠。
EDIT2:
if (noAction == false) { $.ajax({ type: "POST", url: "WebService.asmx/" + webMethod, contentType: "application/json; charset=utf-8", dataType: "json", async: pAsync, data: WSParameters, success: function callFunction(result) { processPOSTResults(result, pType, pNot);}, error: function (xhr, ajaxOptions, thrownError) { alert('Error while communicating with WebAdmin web service. - ' + xhr.status + " " + thrownError); } }); }I'm currently having the problem mentioned in the title and I'm somehow not finding a way to properly replace backsashes with double backslashes, so that I can properly give the string to a webservice as parameters. Let me show you what I tried. Some of these do actually work for some other people, but not for me... I'm currently testing this with FF18.0.1
WSParameters.replace(/\\/g, "\\\\\\\\"); WSParameters.replace("\\", "\\\\\\\\"); WSParameters.replace(/\\/g, "\\\\"); WSParameters.replace(/\\/g, "\\"); WSParameters.replace(/\\/g, "\"); WSParameters.replace("\\", "\\\\");Thanks a lot in advance
EDIT: I should mention that it's somehow parsed into JSON and with firebug I see the backslash in the source string, but not in the JSON view. Maybe there is another way? But somehow it's already failing at the replacement of the backslashes.
EDIT2:
if (noAction == false) { $.ajax({ type: "POST", url: "WebService.asmx/" + webMethod, contentType: "application/json; charset=utf-8", dataType: "json", async: pAsync, data: WSParameters, success: function callFunction(result) { processPOSTResults(result, pType, pNot);}, error: function (xhr, ajaxOptions, thrownError) { alert('Error while communicating with WebAdmin web service. - ' + xhr.status + " " + thrownError); } }); }最满意答案
WSParameters.replace(/\\/g, "\\\\"); 应该这样做,也在FF18中。 请注意,如果您使用JSON.stringify ,则会自动完成。 还要注意许多控制台输出(Firebug等)用引号包围字符串内容,但不要逃避它们。
WSParameters.replace(/\\/g, "\\\\"); should do it, and in FF18 as well. Notice that if you use JSON.stringify, this is done automatically. Also watch out that many console outputs (Firebug etc) do surround string contents with quotes, but do not escape them.
更多推荐
发布评论