Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

posting jquery data

Posted on 2015-01-16
15
Medium Priority
?
171 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:Seven price
  • 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:Seven price
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
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
LVL 9

Author Comment

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

Author Comment

by:Seven price
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:Seven price
ID: 40558042
0
 
LVL 9

Author Comment

by:Seven price
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:Seven price
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:Seven price
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 1000 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:Seven price
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:Seven price
ID: 40558535
There is something missing. Maybe return as a list umm?
0
 
LVL 9

Author Closing Comment

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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

877 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