加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

在ajax表单提交上输入maxlength字段会导致“Uncaught SyntaxErro

发布时间:2020-12-16 03:12:25 所属栏目:百科 来源:网络整理
导读:当我使用ajax提交包含带有“maxlength”属性的文本字段的表单时,我收到一个 javascript错误:Uncaught SyntaxError:Unexpected token u(jquery-1.9.1.min.js:3) 如果我删除maxlength属性一切正常. 我的HTML,将我的页面剥离到最低限度以复制问题: html hea
当我使用ajax提交包含带有“maxlength”属性的文本字段的表单时,我收到一个 javascript错误:Uncaught SyntaxError:Unexpected token u(jquery-1.9.1.min.js:3)

如果我删除maxlength属性一切正常.

我的HTML,将我的页面剥离到最低限度以复制问题:

<html>
    <head>
        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

        <script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
        <script src="/Scripts/jquery.validate.js"></script>
        <script src="/Scripts/jquery.validate.unobtrusive.js"></script>
    </head>
    <body>
        <form action="#" data-ajax="true" id="form0" method="post">
             <input id="deposit" name="numberValue" type="text" class="despositInput" maxlength="8" value="1000">
             <input type="submit" value="go">
        </form>    
    </body>
</html>

无法弄清楚我做错了什么 – 也许Visual Studio模板提供的jquery脚本是不兼容的?我很感激任何帮助,谢谢.

这似乎是 Microsoft.jQuery.Unobtrusive.Validation与jQuery 1.9>组合的错误.

在这个blog中,建议使用js文件的补丁

我重现了你的问题,并通过在你的html中添加一个带有必需属性的div来解决它,以防止将未定义的提供给json解析.

<form action="#" data-ajax="true" id="form0" method="post">
        <div data-valmsg-for="numberValue" data-valmsg-replace="true">deposit not valid</div>
        <input id="deposit" name="numberValue" type="text"  maxlength="8" value="1000">
        <input type="submit" value="go">
    </form>

此问题还有一个Microsoft Connect问题.同时投票决定在微软内部优先考虑.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读