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.
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.
Here is the code from my controller action which is called for ajax.
$project =$_GET['project'];
//Call private function getQuota
$quotaTab = $this->getQuota($project);
$this->_helper->getHelper('viewRenderer')->setNoRender();
Zend_Layout::getMvcInstance()->disableLayout();
// Encode data to return
$return = array(
'quota' => $quotaTab[0],
'usedSpace' => $quotaTab[1],
'usedPercentage' => $quotaTab[2]
);
$return = Zend_Json::encode($return);
$this->getResponse()->setBody($return);
And this is my javascript function containing the ajax function
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 = <?php echo "' ".$this->translate("used")."'";?>;
$('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);
}
});
}
So I debug my script with Firebug, and the exact error that it returns is
"JSON.parse: unexpected non-whitespace character after JSON data
return JSON.parse(json); prototype.js (line 720)"
I have this error in both functions when I use jQuery.ajax. The error happens when trying to evalJSON().
Any idea why it doesn't work anymore ? Could it be because of the encoding(currently UTF-8) of the files ?
Thanks in advance for your help !
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.
[1,2,3]blahblahblah.responsein my javascript function : "{"quota":90,"usedSpace":73.904,"usedPercentage":"82%"}" . Does it seems right ?response