Reputation: 5866
I have Jquery code behaves weirdly. I am doing a complex task but I am almost done with it. Only problem I have is I am trigering a webmethod in C# which works perfectly. That webmethod returns a string value. I am trying to set a cookie with that returned value but it displays [object Object]. How can I display the returned value properly.
$.ajax({
type: "POST",
url: "InsertPost.aspx/insert_post_new_category",
data: "{'CategoryName':'" + user_cat + "','CategoryDescription':''}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data, status) {
if (user_cat.replace(/^\s+|\s+$/g, '') != '') {
$("#demo-input-facebook-theme").tokenInput("add", { name: user_cat, id: data });
$.session.set(encodeURIComponent('Kat_' + user_cat + '_x'), data);
}
}
});
I am having problem with "data" above. that displays [object Object]. How can I fix this
Upvotes: 1
Views: 35
Reputation: 12705
That is because data
is an object
. Try using the correct property of the object data
Upvotes: 1
Reputation: 176886
you used {dataType: "json"}
(in your options to $.ajax()) , because of that to access the value by using data.d
instead of only data
Upvotes: 2