This question already has an answer here:
这个问题在这里已有答案:
- Encode URL in JavaScript? 13 answers
在JavaScript中编码URL? 13个答案
I am communicating to a REST server which is expecting something like http://example.com/1.0/editor/5/bla/26
along with body parameters of x
, y
, and z
. Or maybe instead of /1.0/editor/5/bla/26
, it should be 1.0/editor/5/bla/what about item #26
, but of course with what about item #26
escaped.
我正在与一个REST服务器进行通信,该服务器需要http://example.com/1.0/editor/5/bla/26以及x,y和z的主体参数。或者也许代替/1.0/editor/5/bla/26,它应该是1.0 / editor / 5 / bla /关于项目#26,但当然还有关于项目#26的转义。
There are many post describing how to use jQuery.param() to encode parameters, however, that is not my question. How chould the actual url be created using jQuery of JavaScript?
有很多帖子描述了如何使用jQuery.param()来编码参数,但是,这不是我的问题。如何使用jQuery JavaScript创建实际URL?
$.ajax({
type:'PUT',
url:'/1.0/editor/'+$('#id').val()+'/bla/'+$('#wha').data('id'),
data:{x:x,y:y,z:z},
success: function (error){}
});
1 个解决方案
#1
0
Can you write a javascript RegEx function to replace all spaces with a known character? Or replace it with its HTML equivalent. Then in your backend, just look for that escape character and replace them with the spaces again. It's kind of a work around but depending on your situation it could work.
你能写一个javascript RegEx函数来替换所有已知字符的空格吗?或者用等效的HTML替换它。然后在你的后端,只需查找该转义字符并再次用空格替换它们。这是一种解决方法,但根据你的情况,它可以工作。
#1
0
Can you write a javascript RegEx function to replace all spaces with a known character? Or replace it with its HTML equivalent. Then in your backend, just look for that escape character and replace them with the spaces again. It's kind of a work around but depending on your situation it could work.
你能写一个javascript RegEx函数来替换所有已知字符的空格吗?或者用等效的HTML替换它。然后在你的后端,只需查找该转义字符并再次用空格替换它们。这是一种解决方法,但根据你的情况,它可以工作。