gpt4 book ai didi

jquery - parseJSON 未捕获语法错误 : Unexpected token u

转载 作者:行者123 更新时间:2023-12-03 22:27:48 25 4
gpt4 key购买 nike

这个问题已经让我有点抓狂了几个多小时了。我现在读了很多帖子和文章,对问题的了解很模糊,但不知道原因。我意识到问题是当我在 undefined object 上提交类似 JSON.parse 的内容时。我不明白为什么会这样。我确信它非常简单,而且我确信一旦它被指出,我就会感觉到它是一个工具,但现在如果它解决了问题,我不介意感觉有点傻。

问题是,当我使用以下方法提交表单时,出现以下错误:

Uncaught SyntaxError: Unexpected token u js:1
i.extend.parseJSON js:1
c js:1
u js:1
n.extend.showLabel js:1
n.extend.defaultShowErrors js:1
n.extend.showErrors js:1
n.extend.form js:1
n.extend.valid js:1
(anonymous function)
i.event.dispatch js:1
y.handle

此外,当我将光标从一个字段移动到另一个字段时,我收到此错误:

Uncaught SyntaxError: Unexpected token u js:1
i.extend.parseJSON js:1
c js:1
u js:1
n.extend.showLabel js:1
n.extend.defaultShowErrors js:1
n.extend.showErrors js:1
n.extend.element js:1
n.extend.defaults.onfocusout js:1
r js:1
(anonymous function) js:1
i.event.dispatch js:1
y.handle js:1
i.event.trigger js:1
i.event.simulate js:1
f

这显然阻止我将表单提交给 Controller 进行处理。该错误似乎来自 jquery 库(第 498 行),当它尝试执行以下操作时: return n.JSON.parse(t); (t 未定义)。我正在使用 jquery 1.9.1、bootstrap 2.2.2 和 jqValidate/1.9.0.unobtrusive.js。该表单处于引导模式,如下所示:

@model AModelTestApp.Models.UserModel

<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3>User</h3>
</div>

<div class="modal-body">

@{
var ajaxOptions = new AjaxOptions
{
HttpMethod = "POST",
OnComplete = "Complete"
};
}

@using (Ajax.BeginForm("EditUser", "Home", ajaxOptions, new { id = "userform" }))
{
<div class="row-fluid">
<div class="span12">
@Html.ValidationSummary("Ooops..", new { id = "validateuser", @class = "alert alert-error" })
</div>
</div>

<div class="row-fluid">
<div class="span6">
@Html.LabelFor(m => m.Id)
@Html.TextBoxFor(m => m.Id)

@Html.LabelFor(m => m.Username)
@Html.TextBoxFor(m => m.Username)

@Html.LabelFor(m => m.FirstName)
@Html.TextBoxFor(m => m.FirstName)

@Html.LabelFor(m => m.LastName)
@Html.TextBoxFor(m => m.LastName)
</div>
<div class="span6">
@Html.LabelFor(m => m.Email)
@Html.TextBoxFor(m => m.Email)

@Html.LabelFor(m => m.UserTypeId)
@Html.TextBoxFor(m => m.UserTypeId)

@Html.LabelFor(m => m.Created)
@Html.TextBoxFor(m => m.Created)

@Html.LabelFor(m => m.Active)
@Html.CheckBoxFor(m => m.Active)
</div>
</div>
<div class="row-fluid">
<div class="span1 offset10">
<a id="btnclear" class="btn" href="#">Clear</a>
</div>
</div>
}

</div>

<div class="modal-footer">
<a class="btn" data-dismiss="modal" href="#">Close</a>
<a id="btnsubmit" class="btn btn-info" href="#">Submit</a>
</div>

<script type="text/javascript">
$.validator.unobtrusive.parse($('#userform'));

$('#btnclear').click(function() {
$('input').val('');
$(':checkbox').prop('checked', false);
return false;
});

$('#btnsubmit').click(function () {

$('#userform').validate();
if ($('#userform').valid()) {
$('#userform').submit();
} else {
alert("Something went wrong with the validation")
}

});

function Complete(result) {
alert("Woooo - " + result);
}
</script>

模态加载如下:

<div class="row-fluid">
<div class="span12">
<button id="btnclick" class="btn btn-large btn-block btn-primary">Click Me</button>
</div>
</div>

<div id="mainmodal" class="modal hide fade"></div>

<script type="text/javascript">
$('#btnclick').click(function () {
$.ajax({
url: '@Url.Action("GetUser", "Home")',
type: 'GET',
success: function (result) {
//awss.modal.popup(result);
$('#mainmodal').html(result);
$('#mainmodal').modal('show');
}
});
return;
});
</script>

从此 Controller :

    public ActionResult GetUser()
{
var user = new UserModel
{
Id = 1,
Username = "sbody",
FirstName = "Some",
LastName = "Body",
Email = "sbody@domain.com",
UserTypeId = 6,
Created = new DateTime(2013, 1, 1),
Active = true
};
return PartialView("EditUser", user);
}

ClientValidationEnabled 和 UnobtrusiveJavaScriptEnabled 均在 web.config 中启用。我希望这只是我关注同一问题太久而看不到明显问题的情况。非常感谢任何帮助。谢谢:)

最佳答案

您可以尝试以下操作吗

'$.parseJSON(result)' 

在 ajax 成功函数中使用 parsejson。

关于jquery - parseJSON 未捕获语法错误 : Unexpected token u,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18609565/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com