JavaScript function error. $ .toJSON

4

I'm running a script that was passed to me by third parties. And it is giving the following error:

  

TypeError: $ .toJSON is not a function
QtdeQuartos: $.toJSON(qtdQuartos),

    
asked by anonymous 21.02.2014 / 20:22

2 answers

5

The script probably makes use of the jquery-json library. Download it and add it to your project.

    
21.02.2014 / 20:26
1

toJSON (English) is a method the JavaScript itself is called from your object.

var d = new Date();
var today = d.toJSON();
//Resultado: 2014-02-21T21:57:42.080Z

Receiving this via jQuery, you should use the parseJSON method :

var obj = jQuery.parseJSON( '{ "name": "John" }' );
alert( obj.name === "John" );
    
21.02.2014 / 23:00