Alternative to JSON.stringify () and JSON2.js

I am trying to make a WCF call to a function that takes a single String parameter. When I pass parameters from jQuery, I use JSON.stringify (parameters), where parameters is the name: a collection of values ​​containing the parameters that I want to pass.

My doubts:

  • In my version of IE, JSON is not defined. So, I used the JSON2.js library and included it in the main page of my site.
  • I am still facing the same message. JSON undefined in IE.

Ok, it works fine in Google Chrome.

PS - it's all on .NET.

Script name is json2.js . The values ​​I pass in jQuery are

 data:JSON2.stringify(parameters), contentType: "application/json2; charset=utf-8", dataType: "json2" 

I am using IE8. (Sorry for not submitting this item before, just added)

Please inform.

+4
source share
2 answers

You use json2 in all places where you should ideally use json

Please change your ajax call as

 data:JSON.stringify(parameters), contentType: "application/json; charset=utf-8", dataType: "json" 

In an unrelated side note, you can omit charset and dataType and change the call as follows

 data:JSON.stringify(parameters), contentType: "application/json;", 
+1
source

Instead of JSON2.stringify(parameters) you should use JSON.stringify(parameters) . Also make sure you include the json2.js script in your site.

And if you use IE8, you don't need json2.js at all, since it supports the JSON.stringify method.

+3
source

Source: https://habr.com/ru/post/1435441/


All Articles