Solved

posting jquery data

Posted on 2015-01-16
15
132 Views
Last Modified: 2015-01-20
{"Message":"Type \u0027.\u0027 is not supported for deserialization of an array.","StackTrace":"   at System.Web.Script.Serialization.ObjectConverter.ConvertListToObject(IList list, Type type, JavaScriptSerializer serializer, Boolean throwOnError, IList& convertedList)\r\n  

{"AllRequests":[{"Company":"Company","Total":"45","Inventory":"false","First Name":"FName","Last Name":"LName","Street Addr":"Street","Street Addr 2":"","City":"City","State":"AK","Zip":"111111","Email":"email@eamil.com"}]}

Open in new window


$('#btntable').click( function() {
  var table = $('Table#main').tableToJSON();
  var JSONObject = new Object; 
   var item = table;
        JSONObject.AllRequests = item;  
        JSONstring = JSON.stringify(JSONObject); 
  alert(JSONstring);  
   $.ajax({
                type: "POST",
                url: "/rees.aspx/DatatCity",
                data: JSONstring,
                processData: false,
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function(r) {

Open in new window


         [System.Web.Services.WebMethod]
         public static Detail DatatCity(Detail AllRequests)
         
        {
}
Untitled3.jpg
0
Comment
Question by:sevensnake77
  • 10
  • 5
15 Comments
 
LVL 9

Expert Comment

by:sudheeshthegreat
ID: 40554785
You have a data-type mismatch. The json sent from the client-side and Detail type on the server-side code do not match. The error is due to the server-side code getting an apostrophe/quote character (\u0027) in the serialized json while it is expecting an array.
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 40554822
How can I fix it
0
 
LVL 9

Expert Comment

by:sudheeshthegreat
ID: 40554838
Can you show us the Detail class definition?
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 9

Author Comment

by:sevensnake77
ID: 40555165
It's a web method static class.
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 40555167
WebMethod]
        public string putvalues(string allresults)
        {
            Foreach loop
            // code logic which sets the result value
            result="some value";

            return result;
        }
0
 
LVL 9

Expert Comment

by:sudheeshthegreat
ID: 40557086
You mentioned this
  [System.Web.Services.WebMethod]
         public static Detail DatatCity(Detail AllRequests)
Can you show us how your Detail class is defined?
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 40558042
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 40558064
 [WebMethod]
         public static string AddClient(RequestDetail[] AllRequests)
         {
             // TODO: process ...

             // by the way as a result you could also return a strongly 
             // typed model and not only strings 
             // which could be easily manipulated on the client side
             return "some result";
         }

Open in new window

[Table(Name="dbo.RequestDetail")]
	public partial class Detail : INotifyPropertyChanging, INotifyPropertyChanged
	{
		
		private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
		
		private int _DetailID;
		
		private int _RequestID;
		
		private System.Nullable<int> _RequestTotal;
		
		private System.Nullable<bool> _FromInventoryFlag;
		
		private string _Company;
		
		private string _FirstName;
		
		private string _LastName;
		
		private string _StreetAddress;
		
		private string _StreetAddress2;
		
		private string _City;
		
		private string _State;
		
		private string _Zip;
		
		private string _Email;

Open in new window

\
Nothing is working for me.
0
 
LVL 9

Expert Comment

by:sudheeshthegreat
ID: 40558187
From the code you shared, since you have this URL:
"/rees.aspx/DatatCity"

Open in new window

and this json
{"AllRequests":[{"Company":"Company","Total":"45",...

Open in new window

you need to have an array of some type for the AllRequests parameter.
public static Detail DatatCity(Detail[] AllRequests)

Open in new window

And the Detail class here should have public properties for the json you send, such as Company, Total, Inventory and so on.
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 40558365
not working
[WebMethod]
         public static string AddClient(AllRequests[] AllResults)
         {
             string myself;
             foreach (var c in AllResults)
             {
                 myself = c.Company;
             }

Open in new window

{"AllResults":"[{\"Company\":\"testcompany\"}]"}

Open in new window

public class AllRequests
{
    public string Company { get; set; }
    
}

Open in new window

urrgh why
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 40558370
{"Message":"Cannot convert object of type \u0027System.String\u0027 to type \u0027AllRequests[]\u0027","StackTrace":"   at System.Web.Script.Serialization.ObjectConverter.ConvertObjectToTypeInternal(Object

Open in new window

0
 
LVL 9

Accepted Solution

by:
sudheeshthegreat earned 500 total points
ID: 40558392
Is your url for the AJAX call now
"/rees.aspx/AddClient"
instead of
"/rees.aspx/DatatCity"
?
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 40558413
That part is correct. AddClient is the one I am using. the post in the dom is the json string trying to post. the method will not take it.
0
 
LVL 9

Author Comment

by:sevensnake77
ID: 40558535
There is something missing. Maybe return as a list umm?
0
 
LVL 9

Author Closing Comment

by:sevensnake77
ID: 40559729
it was a quote.
{"AllResults":[{"Company":"testcompany"}]}
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question