当我使用 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这个问题的问题开放。也对该项目进行投票,以便在 Microsoft 内部优先考虑它。
关于ajax - 在 ajax 表单提交上输入 maxlength 字段导致 "Uncaught SyntaxError: unexpected token u",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18161446/