it:ad:jscript:json

IT:AD:JScript:JSON

  • JQuery does not have a JSON Serializer.
    • The argument being that it doesn't need one internally, and can handle it as:

Example:

 $.post("test.php", { name: "John", time: "2pm" } );  
 $.post("test.php", { 'choices[]': ["Jon", "Susan"] });
 $.getJSON("test.js", { name: "John", time: "2pm" }, function(json) {
   alert("JSON Data: " + json.users[3].name);
 });
  • Important: But in all 3 cases (including last) the serialization in these cases is not the same as JSON.Stringify(), instead the data is serialised into a html query string.
  • Therefore, as expressed here use JSON2.js to allow use of Builtin JSON object if available, or use code if not:

That way you can do (see here):

$.ajax({  
  url: "/path/to/url",  
  type: "POST",  
  dataType: "json",  
  contentType: "application/json",  
  data: JSON.stringify({"foo": "bar"}),  
  success: function(){              
    alert("success :-)");  
  },  
  error: function(){  
    alert("fail :-(");  
  }  
}); 

 
  • /home/skysigal/public_html/data/pages/it/ad/jscript/json.txt
  • Last modified: 2023/11/04 03:26
  • by 127.0.0.1