Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
here is my view

JavaScript
<script type="text/javascript">
    $(function () {

        var data1 = [];
        var dist = {
            MemberID: 389104,
            Year: 2015,
            OwnerLastName: 'abcd'
        };

        data1.push('WEBNet');
        data1.push('FindPerson');
        data1.push(dist);
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: 'Service.svc/GetData',
            data: JSON.stringify(data1),
            success: function (data) {
                

            },
            error: function (result) {
                alert(result);
            }
        });

    });

</script>


and i have a service - Service.svc/GetData which returns the person details

when i open the view with internet explorer it is giving me the below error message

[object Object]

Can some one plz tell me where the issue is
Posted
Updated 19-Nov-15 4:42am
v3
Comments
F-ES Sitecore 19-Nov-15 10:44am    
Google for how to use the "error" event in jQuery to get the proper error. Or use Fiddler to examine the body of the result of the ajax query and the proper error could be there. As it stands your question is like phoning a mechanic and saying "my car doesn't work, what is the issue?"
Afzaal Ahmad Zeeshan 19-Nov-15 10:48am    
[object Object] is not an error, it is the type name for the JavaScript object.

As Afzaal Ahmad told [object object] is not a error. [object object] is a basically a array.

you can get the response

JavaScript
$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: 'Service.svc/GetData',
    data: JSON.stringify(data1),
    success: function (data) {

      //use response to get the array.
      alert(data.response);

      //Otherwise use stringyfy method
      alert(JSON.stringify(data));
    },
    error: function (result) {
        console.log('Something went wrong', status, err);
    }
});
 
Share this answer
 
[object object] is an array, not an error. You code works fine. You need to need to display the response according to your response signature.
Let's say if your response contains MemberName, you can do something like-
JavaScript
success: function (data) {
    for(var i=0; i<data.length;>    {
        console.log(data[i].MemberName);
    }
}

This will print all the member names returned from the services in the browser console.


-KR
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900