Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 防止ajax(http)中的特殊字符_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript 防止ajax(http)中的特殊字符

Javascript 防止ajax(http)中的特殊字符,javascript,jquery,ajax,Javascript,Jquery,Ajax,myVar的值是a-b,但不一致,可能是a->b,我如何防止它变成-%3E?如果结果URL变成/pos/myVar,您可以使用'/pos/'+encodeURIComponent(myVar)。i、 e $.ajax({ url: '/pos/' + myVar type: 'GET', success: function(data) {} .. 否则,如果结果URL变为/pos/myVar\u name=myV

myVar的值是a-b,但不一致,可能是a->b,我如何防止它变成-%3E?

如果结果URL变成
/pos/myVar
,您可以使用
'/pos/'+encodeURIComponent(myVar)
。i、 e

 $.ajax({
        url: '/pos/' + myVar
                type: 'GET',
                success: function(data) {}
..
否则,如果结果URL变为
/pos/myVar\u name=myVar\u value
,则应尝试以下操作:-

$.ajax({
        url: '/pos/' + encodeURIComponent(myVar),
        type: 'GET',
        success: function(data) {}
});

此方法将自动在名称和值中对所需数据进行编码。

如果结果URL变为
/pos/myVar
,则可以使用
'/pos/'+encodeURIComponent(myVar)
。i、 e

 $.ajax({
        url: '/pos/' + myVar
                type: 'GET',
                success: function(data) {}
..
否则,如果结果URL变为
/pos/myVar\u name=myVar\u value
,则应尝试以下操作:-

$.ajax({
        url: '/pos/' + encodeURIComponent(myVar),
        type: 'GET',
        success: function(data) {}
});

此方法将自动在名称和值中对所需数据进行编码。

try
encodeURIComponent(myVar)
您是说您不希望它获取编码的数据吗?try
encodeURIComponent(myVar)
您是说您不希望它获取编码的数据吗?