一点背景:我使用的是其产生大致如下东西jQuery用户界面可排序的序列化方法:
类[] =价值和放大器;放大器;一个与放大器;类别[] = ValueTwo和放大器;类别[] = ValueThree
我那么做一个Ajax请求的数据从(POST)发送到Web服务。
我目前使用的HttpUtility.ParseQueryString方法将数据推入一个集合,但出现问题的&放大器;因为它会导致:值(&放大器;一个被切断)
这看起来应该是非常容易解决,但由于某些原因,我画一个空白。什么将是preserve值作为价值与放大器;一个最好的办法
?编辑:添加code样品:
昏暗的数据作为字符串=类别[] =价值和放大器;放大器;一&安培;类别[] = ValueTwo和放大器;类别[] = ValueThree
昏暗httpPOSTData作为System.Collections.Specialized.NameValueCollection
httpPOSTData = HttpUtility.ParseQueryString(数据)
'结果:值,ValueTwo,ValueThree
所需的结果:价值与放大器;其中,ValueTwo,ValueThree
JavaScript的:
serializedSortOrder = $('#分类)。可排序('序列化',{
属性:数据类,
键:类别[]',
EX pression:/(.*)/
});
解决方案
jQuery UI的坏。 jquery.ui.sortable.js 411线:
如果(RES)str.push((o.key || RES [1] +'[]')+'='+(o.key&安培;&放大器;○ .EX pression水库[1]:资源[2]));
哎呀,有人忘了连接codeURIComponent()
键和值部分倾倒到字符串之前。
A bit of background: I'm using the jQuery UI sortable serialize method which produces something along the following:
category[]=Value & One&category[]=ValueTwo&category[]=ValueThree
I then make an Ajax request to send the data off (POST) to a web service.
I'm currently using the HttpUtility.ParseQueryString method to push the data into a collection, but a problem arises with the & as it results in: "Value" ("& One" is cut off).
This seems like it should be incredibly easy to fix, but for some reason I'm drawing a blank. What would be the best way to preserve the value as "Value & One"?
Edit: Adding code samples:
Dim data As String = "category[]=Value & One&category[]=ValueTwo&category[]=ValueThree"
Dim httpPOSTData As System.Collections.Specialized.NameValueCollection
httpPOSTData = HttpUtility.ParseQueryString(data)
'Result: "Value ,ValueTwo,ValueThree"
'Desired Result: "Value & One,ValueTwo,ValueThree"
Javascript:
serializedSortOrder = $('#Categories').sortable('serialize',{
attribute:'data-category',
key:'category[]',
expression: /(.*)/
});
解决方案
jQuery UI is broken. Line 411 of jquery.ui.sortable.js:
if(res) str.push((o.key || res[1]+'[]')+'='+(o.key && o.expression ? res[1] : res[2]));
Whoops, somebody forgot to encodeURIComponent()
the key and value parts before dumping into the string.