Note that there are some explanatory texts on larger screens.

plurals
  1. POparseJSON Uncaught SyntaxError: Unexpected token u
    primarykey
    data
    text
    <p>This problem has been driving me slightly nuts for more than a few hours now. I've read so many posts and articles now that I have a vague understanding of the problem but not the cause. I realise the problem is that when I submit something like JSON.parse on an object that's undefined. I cannot figure out why that is though. I'm sure it's very simple and I'm sure I'll feel a tool once it's pointed out, but for now I don't mind feeling a bit silly if it sorts the problem.</p> <p>The problem is that when I submit the form using the below methods I get the following error:</p> <pre><code>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 </code></pre> <p>Also when I move the cursor from field to field I get this error:</p> <pre><code>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 </code></pre> <p>This obviously prevents me from submitting the form to the controller to be processed. The error seems to be from the jquery library (line 498) when it tries to: return n.JSON.parse(t); (t is undefined). I'm using jquery 1.9.1, bootstrap 2.2.2 and jqValidate/1.9.0.unobtrusive.js. The form is in a bootstrap modal and looks as follows:</p> <pre><code>@model AModelTestApp.Models.UserModel &lt;div class="modal-header"&gt; &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt; &lt;h3&gt;User&lt;/h3&gt; &lt;/div&gt; &lt;div class="modal-body"&gt; @{ var ajaxOptions = new AjaxOptions { HttpMethod = "POST", OnComplete = "Complete" }; } @using (Ajax.BeginForm("EditUser", "Home", ajaxOptions, new { id = "userform" })) { &lt;div class="row-fluid"&gt; &lt;div class="span12"&gt; @Html.ValidationSummary("Ooops..", new { id = "validateuser", @class = "alert alert-error" }) &lt;/div&gt; &lt;/div&gt; &lt;div class="row-fluid"&gt; &lt;div class="span6"&gt; @Html.LabelFor(m =&gt; m.Id) @Html.TextBoxFor(m =&gt; m.Id) @Html.LabelFor(m =&gt; m.Username) @Html.TextBoxFor(m =&gt; m.Username) @Html.LabelFor(m =&gt; m.FirstName) @Html.TextBoxFor(m =&gt; m.FirstName) @Html.LabelFor(m =&gt; m.LastName) @Html.TextBoxFor(m =&gt; m.LastName) &lt;/div&gt; &lt;div class="span6"&gt; @Html.LabelFor(m =&gt; m.Email) @Html.TextBoxFor(m =&gt; m.Email) @Html.LabelFor(m =&gt; m.UserTypeId) @Html.TextBoxFor(m =&gt; m.UserTypeId) @Html.LabelFor(m =&gt; m.Created) @Html.TextBoxFor(m =&gt; m.Created) @Html.LabelFor(m =&gt; m.Active) @Html.CheckBoxFor(m =&gt; m.Active) &lt;/div&gt; &lt;/div&gt; &lt;div class="row-fluid"&gt; &lt;div class="span1 offset10"&gt; &lt;a id="btnclear" class="btn" href="#"&gt;Clear&lt;/a&gt; &lt;/div&gt; &lt;/div&gt; } &lt;/div&gt; &lt;div class="modal-footer"&gt; &lt;a class="btn" data-dismiss="modal" href="#"&gt;Close&lt;/a&gt; &lt;a id="btnsubmit" class="btn btn-info" href="#"&gt;Submit&lt;/a&gt; &lt;/div&gt; &lt;script type="text/javascript"&gt; $.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); } &lt;/script&gt; </code></pre> <p>The modal is loaded as follows:</p> <pre><code>&lt;div class="row-fluid"&gt; &lt;div class="span12"&gt; &lt;button id="btnclick" class="btn btn-large btn-block btn-primary"&gt;Click Me&lt;/button&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="mainmodal" class="modal hide fade"&gt;&lt;/div&gt; &lt;script type="text/javascript"&gt; $('#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; }); &lt;/script&gt; </code></pre> <p>From this controller:</p> <pre><code> 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); } </code></pre> <p>Both ClientValidationEnabled and UnobtrusiveJavaScriptEnabled are enabled in the web.config. I'm hoping it's just a case of me looking at the same problem for too long and can't see the obvious. Any help greatly appreciated. Thanks :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload