1

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

2 Answers 2

2

you used {dataType: "json"} (in your options to $.ajax()) , because of that to access the value by using data.d instead of only data

Sign up to request clarification or add additional context in comments.

2 Comments

what does "d" represents? I need to wait 10 mins to mark it as answeres. thank you very much, it works
@Borsel - data repsent json object and to get value of it you need to write data.d so is value of the object return by you..you can check jquery ajax function that will give you more clear idea
1

That is because data is an object. Try using the correct property of the object data

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.