Solved

posting jquery data

Posted on 2015-01-16
15
123 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
C#, asp.net MVC, sql server, LINQ 3 32
Javascript to set controls visibility 5 34
javascript: add id amounts 5 46
Expression Evaluater 3 24
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

776 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