I'm trying to use jQuery and Ajax and I use this method. but I get the error $.toJSON is not a function in my firebug . where is the problem? I use jquery 1.3.2 . thanks
$(document).ready(function () { $("#S1").click(function () { $("#t1").slideToggle("fast"); $("#S1").css("background-color", "yellow"); var ID = $("#HiddenField2").attr("Value"); var params = new Object(); params.Key = ID; $.ajax({ type: "POST", url: "viewMessages.aspx/readen", data: $.toJSON(params), contentType: "application/json", dataType: "json", success: function () { } }); }); });
The toJSON() method returns a date object as a string, formatted as a JSON date.
Conclusion # The "response. json is not a function" error occurs when we call the json() method on an object that is not the Response object that resolves from the promise the fetch() method returns, or call the json() method on the return value from calling an axios method.
The toJSON() function is useful for making sure ES6 classes get serialized correctly. For example, suppose you have a custom JavaScript error class. By default, JavaScript isn't great with serializing errors. The below script prints {"status":404} , no error message or stack trace.
That's correct.
There is no $.toJSON()
function: http://api.jquery.com/jQuery.toJSON. Perhaps you want to use JSON.stringify()
instead.
You need to include the jquery-json
library from http://code.google.com/p/jquery-json/ on your page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With