Javascript encodeURIComponent()不';t似乎编码'+';包含dojo.xhrPost()的字符

Javascript encodeURIComponent()不';t似乎编码'+';包含dojo.xhrPost()的字符,javascript,dojo,urlencode,Javascript,Dojo,Urlencode,我试图对一个URL进行编码,该URL在POST请求中作为参数传递。URL包含“+”字符,javascript的encodeURIComponent()似乎没有对这些字符进行编码。你知道为什么会这样吗 代码: 实际网址: http://......../images/I/41zMWkv3+9L._CLa|500,500|41c4imMJhOL.jpg,31PAFct+UsL.jpg_.jpg 编码URL: http://......../images/I/41zMWkv3+9L._CLa%7C5

我试图对一个URL进行编码,该URL在POST请求中作为参数传递。URL包含“+”字符,javascript的encodeURIComponent()似乎没有对这些字符进行编码。你知道为什么会这样吗

代码:

实际网址:

http://......../images/I/41zMWkv3+9L._CLa|500,500|41c4imMJhOL.jpg,31PAFct+UsL.jpg_.jpg
编码URL:

http://......../images/I/41zMWkv3+9L._CLa%7C500,500%7C41c4imMJhOL.jpg,31PAFct+UsL.jpg_.jpg
正在对“|”字符进行编码,但未对“+”字符进行编码

这将导致在服务器端将URL解码为以下URL(“+”替换为“”):

http://......../images/I/41zMWkv3 9L._CLa|500,500|41c4imMJhOL.jpg,31PAFct UsL.jpg_.jpg
我将非常感谢您的帮助


谢谢

当我使用
encodeURIComponent
decodeURIComponent()
处理查询字符串时,我也遇到了这个特殊的问题

我不得不使用
replace(“,”+”)

我说这是正常的,因为在这个网站上看,它也使用替换 该网站建议在解码时将+替换为
,因为unescape不会

我试着用
+
编码
%2B

或者使用
decodeURIComponent()
但您不需要

您可以使用
var url=document.location.search在变量中处理url.html

重复:

search          Returns the query portion of a URL
http://localhost:8100/index2?json_data=demo_title%24+Demo+title+%23+proc1_script%24+
示例:

search          Returns the query portion of a URL
http://localhost:8100/index2?json_data=demo_title%24+Demo+title+%23+proc1_script%24+
使用
文档.位置.搜索

?json_data=demo_title%24+Demo+title+%23+proc1_script%24+
使用
replace
或其他方法更改站点url后

document.location.href="index2"+url;
您可以使用
index.html
exercise.html
更改索引2(您必须知道)

您可以在此页面上查找所有字符的编码

更新

您可以尝试使用以下代码:

var url = "http://........"
 url += "&url=" + encodeURIComponent(params.url);
//There is a error because miss `?` then you replace `"?url="` else leave so

 var deferred = dojo.xhrPost(xhrArgs);
  var xhrArgs= {
        url: url,
        headers: { "X-Requested-With": null },
        sync: true,
        load: function(responseObject, ioArgs) {
            console.info(".....................");
            params.onSuccess();
        },
        error: function(error) {
            console.error("Error uploading image" + error);
            params.onError();
        }
    });

什么是
params

当我使用
encodeURIComponent
decodeURIComponent()
处理查询字符串时,我也遇到了这个特殊的问题

我不得不使用
replace(“,”+”)

我说这是正常的,因为在这个网站上看,它也使用替换 该网站建议在解码时将+替换为
,因为unescape不会

我试着用
+
编码
%2B

或者使用
decodeURIComponent()
但您不需要

您可以使用
var url=document.location.search在变量中处理url.html

重复:

search          Returns the query portion of a URL
http://localhost:8100/index2?json_data=demo_title%24+Demo+title+%23+proc1_script%24+
示例:

search          Returns the query portion of a URL
http://localhost:8100/index2?json_data=demo_title%24+Demo+title+%23+proc1_script%24+
使用
文档.位置.搜索

?json_data=demo_title%24+Demo+title+%23+proc1_script%24+
使用
replace
或其他方法更改站点url后

document.location.href="index2"+url;
您可以使用
index.html
exercise.html
更改索引2(您必须知道)

您可以在此页面上查找所有字符的编码

更新

您可以尝试使用以下代码:

var url = "http://........"
 url += "&url=" + encodeURIComponent(params.url);
//There is a error because miss `?` then you replace `"?url="` else leave so

 var deferred = dojo.xhrPost(xhrArgs);
  var xhrArgs= {
        url: url,
        headers: { "X-Requested-With": null },
        sync: true,
        load: function(responseObject, ioArgs) {
            console.info(".....................");
            params.onSuccess();
        },
        error: function(error) {
            console.error("Error uploading image" + error);
            params.onError();
        }
    });

什么是
params

您看到的是该方法的特定行为。@dandavis-您能详细说明一下吗?根据文档()encodeURIComponent()应该对“+”字符进行编码。我在这里遗漏了什么吗?您看到的是该方法的特定行为。@dandavis-您能详细说明一下吗?根据文档()encodeURIComponent()应该对“+”字符进行编码。我错过什么了吗?对不起,我失去了你。似乎可以很好地使用encodeURIComponent();正在对“+”字符进行编码。但是,为什么它在我的代码中不起作用?我用错了吗?谢谢。@Soon带着控制台看/看错误?你的代码似乎是正确的对不起,我把你弄丢了。似乎可以很好地使用encodeURIComponent();正在对“+”字符进行编码。但是,为什么它在我的代码中不起作用?我用错了吗?谢谢。@Soon带着控制台看/看错误?您的代码似乎是正确的