Solved

posting jquery data

Posted on 2015-01-16
15
113 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
Comment Utility
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
Comment Utility
How can I fix it
0
 
LVL 9

Expert Comment

by:sudheeshthegreat
Comment Utility
Can you show us the Detail class definition?
0
 
LVL 9

Author Comment

by:sevensnake77
Comment Utility
It's a web method static class.
0
 
LVL 9

Author Comment

by:sevensnake77
Comment Utility
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
Comment Utility
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
Comment Utility
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 9

Author Comment

by:sevensnake77
Comment Utility
 [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
Comment Utility
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
Comment Utility
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
Comment Utility
{"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
Comment Utility
Is your url for the AJAX call now
"/rees.aspx/AddClient"
instead of
"/rees.aspx/DatatCity"
?
0
 
LVL 9

Author Comment

by:sevensnake77
Comment Utility
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
Comment Utility
There is something missing. Maybe return as a list umm?
0
 
LVL 9

Author Closing Comment

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

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now