Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have serialized data into this form"
C#
string json1 = [{"id":1,"col1":"11","col2":"22","col3":"33"}]

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "javascript", "Javascript:GetDateTime(" + json1 + ");", true);

How do I change the format of json1 so I do not get this error:
"Error Code: Status: [object Object] Ex: error"

jQuery Ajax
JavaScript
    <script  type="text/javascript src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
        function GetDateTime(json1) {
            $.ajax
            ({
                type: "POST",
                url: "Default.aspx/GetServerDateTime",
                data: json1,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (result) {
                    alert(result.d);
                },
                error: function (status, ex) {
                    alert("Error Code: Status: " + status + " Ex: " + ex);
                }
            });
        }
    </script>
Posted
Updated 27-Oct-14 3:50am
v3
Comments
RaisKazi 27-Oct-14 10:12am    
Your JQuery/Ajax code looks OK. Problem looks to be in your server side string variable json1. Try by using double quotes or escape character.

1 solution

Don't do like this.

Always Serialize - JSON Serialization and Deserialization in ASP.NET[^].
 
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