title: JQuery, Unexpected token u
body: <p>I have ajax form on my view, but when I try to submit it I get the following error:
  <strong>Opera 12.16</strong> console output:</p>
  
  <pre><code>Error thrown at line 541, column 3 in &lt;anonymous function: parseJSON&gt;(data) in http://mysite/Scripts/jquery-1.9.1.js:
      return window.JSON.parse( data );
  called from line 33, column 2 in onError(error, inputElement) in http://mysite/Scripts/jquery.validate.unobtrusive.js:
      var container = $(this).find("[data-valmsg-for='" + inputElement[0].name + "']"),
  called via Function.prototype.apply() from line 818, column 3 in &lt;anonymous function: proxy&gt;() in http://mysite/Scripts/jquery-1.9.1.js:
      return fn.apply( context || this, args.concat( core_slice.call( arguments ) ) );
  called from line 619, column 7 in &lt;anonymous function: showLabel&gt;(element, message) in http://mysite/Scripts/jquery.validate.js:
      this.settings.errorPlacement(label, $(element));
  called from line 581, column 6 in &lt;anonymous function: defaultShowErrors&gt;() in http://mysite/Scripts/jquery.validate.js:
      this.showLabel(this.successList[i]);
  called from line 377, column 5 in &lt;anonymous function: showErrors&gt;(errors) in http://mysite/Scripts/jquery.validate.js:
      this.defaultShowErrors();
  called from line 326, column 4 in &lt;anonymous function: form&gt;() in http://mysite/Scripts/jquery.validate.js:
      this.showErrors();
  called from line 72, column 5 in &lt;anonymous function: validate&gt;(event) in http://mysite/Scripts/jquery.validate.js:
      if (validator.form())
  called via Function.prototype.apply() from line 3073, column 5 in &lt;anonymous function: dispatch&gt;(event) in http://mysite/Scripts/jquery-1.9.1.js:
      ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler )
  called via Function.prototype.apply() from line 2749, column 4 in &lt;anonymous function: elemData.handle&gt;(e) in http://mysite/Scripts/jquery-1.9.1.js:
      return typeof jQuery !== core_strundefined &amp;&amp; (!e || jQuery.event.triggered !== e.type) ?
  </code></pre>
  
  <p><strong>My form:</strong></p>
  
  <pre><code>@using(Ajax.BeginForm("action",
                         "controller",
                         null,
                         new AjaxOptions
                             {
                                 HttpMethod = "Post",
                                 InsertionMode = InsertionMode.InsertAfter,
                                 OnComplete = "completeRequest",
                                 UpdateTargetId = "update-div"
                             }, new { @id = "my-ajax-form" }))
  {...}
  </code></pre>
  
  <p><strong>My java script file with <code>completeRequest</code> method</strong></p>
  
  <pre><code>$(document).ready(function () {
      initializeSubmit();
  });    
  
  function initializeSubmit(){
      $('#myinput').change(function() {
          alert(); // alert works and after that I get that big error in browsers console
          $('#my-ajax-form').submit();
      });
  }
  
  function completeRequest(data) {
          var result = $.parseJSON(data.responseText);
  
          // do stuff
      }
  </code></pre>
  
  <p><strong>Google chrome</strong> browser's console output:</p>
  
  <pre><code>ncaught SyntaxError: Unexpected token u       jquery-1.9.1.js:541
  jQuery.extend.parseJSON                       jquery-1.9.1.js:541
  onError                                       jquery.validate.unobtrusive.js:41
  proxy                                         jquery-1.9.1.js:818
  $.extend.showLabel                            jquery.validate.js:698
  $.extend.defaultShowErrors                    jquery.validate.js:655
  $.extend.showErrors                           jquery.validate.js:410
  $.extend.form                                 jquery.validate.js:358
  (anonymous function)                          jquery.validate.js:83
  jQuery.event.dispatch                         jquery-1.9.1.js:3074
  elemData.handle                               jquery-1.9.1.js:2750
  jQuery.event.trigger                          jquery-1.9.1.js:2986
  (anonymous function)                          jquery-1.9.1.js:3677
  jQuery.extend.each                            jquery-1.9.1.js:648
  jQuery.fn.jQuery.each                         jquery-1.9.1.js:270
  jQuery.fn.extend.trigger                      jquery-1.9.1.js:3676
  jQuery.fn.(anonymous function)                jquery-1.9.1.js:7403
  (anonymous function)                          *******my-javascript-file.js:171******
  jQuery.event.dispatch                         jquery-1.9.1.js:3074
  elemData.handle                               jquery-1.9.1.js:2750
  </code></pre>
  
  <p><strong>my-javascript-file.js:171</strong> is actually line, where submit is called:</p>
  
  <pre><code>function initializeSubmit(){
          $('#myinput').change(function() {
              alert(); // alert works and after that I get that big error in browsers console
  171:       $('#my-ajax-form').submit();
          });
      }
  </code></pre>
  
  <p>And here is actual jquery source code, which throws the exception:</p>
  
  <pre><code>if ( !(eventHandle = elemData.handle) ) {
              eventHandle = elemData.handle = function( e ) {
                  // Discard the second event of a jQuery.event.trigger() and
                  // when an event is called after a page has unloaded
                  return typeof jQuery !== core_strundefined &amp;&amp; (!e || jQuery.event.triggered !== e.type) ?
          2750: jQuery.event.dispatch.apply( eventHandle.elem, arguments ) :
                      undefined;
              };
              // Add elem as a property of the handle fn to prevent a memory leak with IE non-native events
              eventHandle.elem = elem;
          }
  </code></pre>
  
  <p>And <strong>jQuery</strong> line <strong>541</strong></p>
  
  <pre><code>parseJSON: function( data ) {
          // Attempt to parse using the native JSON parser first
          if ( window.JSON &amp;&amp; window.JSON.parse ) {
  541:                    return window.JSON.parse( data );
  //Uncaught SyntaxError: Unexpected token u
          }
  </code></pre>
  
  <p>Is this jQuery bug? Or what can be the issue? I'm stuck here, already, for about several hours. </p>
  
  <p><strong>P.S.</strong> The error is thrown <strong>BEFORE</strong> submit. Form is not posted yet.</p>
  
  <p>This is error state in chrome debugger.
  <img src="https://i.stack.imgur.com/zUtQk.png" alt="enter image description here"></p>
  
  <p><strong>P.P.S.</strong> I've found the strange solution: I added <code>@Html.ValidationMessageFor()</code> helpers for all model properties, and I've posted the form successfully, got the server side and hit my break point in controller. Still can not understand what is this problem in.</p>