简体   繁体   中英

unterminated string constant error only with IE 9

Ok i got this error in IE 8 and 9, this is Ajax call

$('#$id').ajaxForm({
beforeSend: function() {
$("#{$this->name}_div").hide();
$("#{$this->name}_message").hide(); 
$("#{$this->name}_message").show().html('<img src="$gif">');
},
success: function(response)
{
     var response = JSON.parse(response);
     if (response.error != 'undefined')
{
...
}

}

Problem is in this line of JavaScript code

 var response = JSON.parse(response);

My Javescript, broke, script works in othere browsers and in Internet explorer 10, i am worried if someone with older IE try to visit my site. Is there any solution for this error?

Why are you trying to parse the JSON yourself? ajaxForm provides a dataType option for that:

$('#$id').ajaxForm({
    beforeSend: function() {
        $("#{$this->name}_div").hide();
        $("#{$this->name}_message").hide(); 
        $("#{$this->name}_message").show().html('<img src="$gif">');
    },
    dataType: 'json',
    success: function(response){
       if (response.error != 'undefined') {
           ...
       }
    }
});

On the other hand, if there's something invalid in your JSON that other browsers just happen to be tolerating, then pretty much the only answer is to fix your JSON.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM