Javascript error function. $. toJSON

Asked

Viewed 94 times

4

I’m running a script that was passed to me by a third party. And this is making the following mistake:

Typeerror: $.toJSON is not a Function
QtdeQuartos: $.toJSON(qtdQuartos),

  • 1

    You imported the third party file and jquery?

2 answers

5

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

1

toJSON (English) is a method of 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 method parseJSON (English):

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.