使用 asp.net 2.0 框架时出现此错误。我在网上搜索了但没有找到答案,提前谢谢大家。以下是说明。
<sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
<section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
<section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
</sectionGroup>
</sectionGroup>
</sectionGroup>
上面是 Web.config 中的配置部分。使用[AjaxMethod(HttpSessionStateRequirement.ReadWrite)]
属性定义服务器端的ajax方法。方法如下:public virtual AjaxResult Add(string[] values, string[] valueParameters, int editMode)
。当其中一个string
值string[]
包含 \, 或 ,\ 时会失败,服务器获取的参数被 ',' 分成两部分,如果是 'H\,H' 则变为 'H\'和 '',如果是 'H,\H' 它变成了 '' 和 '\H'。这是消息:
"{'IsValid':false,'Values':[],'Message':'索引超出了数组的范围。','UnformattedMessage':null,'Type':6}"
我已经调试过了,Ajax框架通过'"' + o.replace(/(["\\])/g, '\\$1') + '"'
正则表达式将输入字符串转换成Json。例如,
"DSF\,DF"
将被翻译成
"DSF\\,DF"
我认为这很好,但 asp.net 框架无法正确识别它。
请帮我。