title: How to fix or diagnose Uncaught SyntaxError: Unexpected token o in Javascript
body: <p>Shopping cart implements exception logging from browser using:</p>
  <pre><code>window.onerror = function (errorMsg, url, lineNumber, column, errorObj) {
      $.post('/Home/Error',
      {
          &quot;errorMsg&quot;: errorMsg,
          &quot;url&quot;: url,
          &quot;lineNumber&quot;: lineNumber,
          &quot;column&quot;: column,
          &quot;errorobj&quot;: JSON.stringify(errorObj)
      });
  </code></pre>
  <p>This logs strange errors about token <code>o</code> :</p>
  <blockquote>
  <p>Error Uncaught SyntaxError: Unexpected token o</p>
  </blockquote>
  <p>This exception occurs 4-8 times again in same second form same IP address.
  After some time it occurs again in 4-8 times.
  There are small number of IP addresses from which its occurs. It looks like they are human IP addresses, not robots.</p>
  <p>URLs and column numbers vary a bit:</p>
  <blockquote>
  <p>Line 1 Column 2<br />
  Line 1 Column 10 Object {}<br />
  Line 1 Column 10 Object {}<br />
  Line 1 Column 9 Object {}<br />
  Line 1 Column 1 Object {}</p>
  </blockquote>
  <p>Line number is 1 always:</p>
  <blockquote>
  <p>object is empty.</p>
  </blockquote>
  <p>There are 4 different column numbers:  1,2,9,10</p>
  <p>HTTP headers in error posting request are:</p>
  <pre><code>Connection  keep-alive
  Content-Length  165
  Content-Type    application/x-www-form-urlencoded; charset=UTF-8
  Accept  */*
  Accept-Encoding gzip, deflate
  Accept-Language et-EE,et;q=0.8,en-US;q=0.6,en;q=0.4,de;q=0.2
  Cookie  __utma=117734412.255164026.1415001424.1415340483.1417604639.4; __utmz=117734412.1415001424.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); __utma=56901291.1707816279.1415687607.1418885975.1424090658.4; __utmz=56901291.1415687607.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none); Eeva_Session=5BA67BC05470AD4E1BA6B3F6
  User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36
  X-Requested-With    XMLHttpRequest
  </code></pre>
  <p>How to fix or diagnose this exception ?
  Cart contains no o object probably. First line is  <code>&lt;!DOCTYPE html&gt;</code></p>
  <p>User agent part without OS is always mostly the same:</p>
  <blockquote>
  <p>Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36</p>
  </blockquote>
  <p>or</p>
  <blockquote>
  <p>Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36</p>
  </blockquote>
  <p>or</p>
  <blockquote>
  <p>User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36</p>
  </blockquote>
  <p>So it looks like it occurs in this particular browser only.</p>
  <p>How to fix or diagnose this error so that it does not occur?</p>
  <p>ASP.NET MVC4, jQuery, jQuery ui and few common jQuery plugins are used.</p>
  <p><strong>Update</strong></p>
  <p>Those pages contain few ajax calls. /Store/Browse contains ajax to add item to cart:</p>
  <pre><code>   request = $.post('/Store/AddToCart',
          serializedData, function (response) {
              $(&quot;#cart-status&quot;).text(response.Total);
              $inputs.prop(&quot;disabled&quot;, false);
              var xx = $form[0].quantity;
              $($form[0].quantity).css(&quot;background-color&quot;, &quot;green&quot;);
              showMessage(response.Message);
              showFadeOutMessage(response.Message);
          })
             .fail(function (jqXHR, textStatus, errorThrown) {
                 alert('Viga ' + textStatus);
             })
            .always(function () {
                $inputs.prop(&quot;disabled&quot;, false);
            });
  </code></pre>
  <p>Store/Detail contains ajax to retrieve images:</p>
  <pre><code>  $.get(
              '/Store/Similar?product=TN_8627&amp;category=3',
                    {
                        per_page: per_page,
                        page: page,
                        first: carousel.first,
                        last: carousel.last
                    },
                    function(data) {
                        mycarousel_itemAddCallback(carousel, first, last, data, page);
                    }
                );
  </code></pre>
  <p>error occurs in both pages.
  JSON.Parse() which can cause this error according to  <a href="https://stackoverflow.com/questions/8081701/i-keep-getting-uncaught-syntaxerror-unexpected-token-o?lq=1">I keep getting &quot;Uncaught SyntaxError: Unexpected token o&quot;</a> answer is not used.</p>
  <p>How to fix or diagnose them ?</p>