0

I am trying to return two json objects.But i am able to receive only one. Am i doing wrong? Success is just showing 'success' as string when i try to alert this but otherwise in firebug it has value=true .So, it must show true which is its value and not the variable instead.

I am returning below in which data is receiving but success is not showing its value. How should i extract the value of success in my $.ajax funtion..

 return Json(new { data = obj, success = isSuccess });

$.ajax({
            type: "POST",
            url: "controller/Action",
            data: "",
            success: function (data, success) {
                debugger;
                alert(success);

            },

2 Answers 2

2

You will get response data as a first argument.

$.ajax({
    type: "POST",
    url: "controller/Action",
    data: "",
    success: function (response) {
        console.log(response.success);
    }
})
Sign up to request clarification or add additional context in comments.

Comments

1

you are sending both obj and isSuccess flag in one object as JSON

Json(new { data = obj, success = isSuccess });

so finally in ajax call success event you will get that wrapper object only, which will have two properties data and success.

$.ajax({
    type: "POST",
    url: "controller/Action",
    data: "",
    success: function (wrapperObj) {
        console.log(wrapperObj.success); // this will be your isSuccess flag.
        if(wrapperObj.success)
        {            
            console.log(wrapperObj.data); // this will be your obj.                 
        }
    }
})

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.