jQuery JSON SyntaxError:仅在FIREFOX上使用JSON.parse

时间:2014-08-11 13:20:49

标签: javascript jquery json firefox

嗨大家问题很简单,但我无法解决它 - 它只发生在FIREFOX这里是代码:

$.ajax({
     type: "POST",
     url: validUrl,
     data: serializedForm,
     beforeSend: function(x) {
      if(x && x.overrideMimeType) {
       x.overrideMimeType(jsonMimeType);
      }
     },
     dataType: "json",
     success: function(resp){

        console.log(resp);
        var arr = jQuery.parseJSON(resp);
     }
    });

console.log给出了这样的答案:

  

[“emailAddress.used”,“register.confirmRulesError”]

我有错误:

  

var arr = jQuery.parseJSON(resp);

完整错误:

  

SyntaxError:JSON.parse:JSON数据第1行第1列的意外字符

这只发生在FireFox中,我无法找到解决方案。

响应头是:Content-Type application / json; charset = UTF-8

任何想法如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

尝试不用解析json你的数据。因为,

响应数据看起来像这样,

 ["emailAddress.used", "register.confirmRulesError"]

如果你要解析,需要在json中使用key,value对,这就是它的例外。

{["emailAddress.used", "register.confirmRulesError"]}//not allowed.