Note that there are some explanatory texts on larger screens.

plurals
  1. POError with JSON in javascript : unexpected non-whitespace character after JSON data
    text
    copied!<p>My question is about an error I have when I use jQuery.ajax in my javascript function. I searched and found similar question, but none of these questions helped me.</p> <p>So, what's really weird is that it was working before. I spent a few days working on translations problems with UTF-8 and when I tried it again after, it was working anymore. I can't see what happened so maybe you can help me find out. </p> <p>Here is the code from my controller action which is called for ajax.</p> <pre><code>$project =$_GET['project']; //Call private function getQuota $quotaTab = $this-&gt;getQuota($project); $this-&gt;_helper-&gt;getHelper('viewRenderer')-&gt;setNoRender(); Zend_Layout::getMvcInstance()-&gt;disableLayout(); // Encode data to return $return = array( 'quota' =&gt; $quotaTab[0], 'usedSpace' =&gt; $quotaTab[1], 'usedPercentage' =&gt; $quotaTab[2] ); $return = Zend_Json::encode($return); $this-&gt;getResponse()-&gt;setBody($return); </code></pre> <p>And this is my javascript function containing the ajax function</p> <pre><code>function changeQuota() { var fileset = document.getElementById('fileset'); jQuery.ajax({ url: '/filesets/quota/', data: ({ project: fileset.value, ajaxCall: true}), success: function(response) { //Decode the JSON response var result = response.evalJSON(); // Set the new value of current quota $('currentQuota').value = result.quota; var strUsed = &lt;?php echo "' ".$this-&gt;translate("used")."'";?&gt;; $('usedQuota').innerHTML = result.usedPercentage.concat(strUsed); var suggestQuota = Math.round(parseFloat(result.quota) + parseFloat(result.quota/10)); $('quota').value = suggestQuota; $('usedSpace').value = Math.round(result.usedSpace); } }); } </code></pre> <p>So I debug my script with Firebug, and the exact error that it returns is <strong>"JSON.parse: unexpected non-whitespace character after JSON data</strong><br> <strong>return JSON.parse(json); prototype.js (line 720)"</strong></p> <p>I have this error in both functions when I use jQuery.ajax. The error happens when trying to evalJSON().</p> <p>Any idea why it doesn't work anymore ? Could it be because of the encoding(currently UTF-8) of the files ? </p> <p>Thanks in advance for your help ! </p> <p>P.S. Maybe it's not linked, but when I open prototype.js with Zend Studio, I have some warnings and 2 errors("missing semi-colon" at line 4235 and "Syntax error on token ",", . expected" at line 4000. When I noticed that, I downloaded latest version and it didn't change.</p>
 

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