views:

25

answers:

1

I have looped through a simple gathering data and pushing it into an array. I am then trying to send that array to a page method (.aspx). There is something about the array that it does not like I think. Here is my code:

//packaging table data for submit to server
            $("#saveToDB").click(function() {
                var dataForSubmit = new Array();
                //gather all data to array except the "delete" cell, .rowToDelete
                $('#QueueTable tbody td:not(.rowToDelete)').each(function() {
                    dataForSubmit.push($(this).html());

                });
                //test the array
                //alert(dataForSubmit);

                //send array to method
                $.ajax({
                    type: "POST",
                    url: "DailyReceipts.aspx/saveData",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    data: dataForSubmit,
                    success: function(msg) {
                        $.jGrowl('Your data has been successfully saved.', { header: 'Important' });
                        $('#result').append(msg.d)
                    },
                    error: function() {
                        $.jGrowl('An error has occured in saving the data.', { header: 'Important' });
                    }
                });
            });
+2  A: 

Just append whatever parameter it's expecting on the data argument like this:

data: "paramName=" + dataForSubmit,

or, alternatively:

data: { paramName : dataForSubmit },
Nick Craver
I changed it but it is still reaching my error code..
Matt
@Matt - Put this in for your error handler to see what the error is: `error:function (xhr, opt, aError){ alert(xhr.status); alert(aError); }`
Nick Craver
Matt
@Matt - That means a server error, something's blowing up on the asp.net side of things, can you hook up a debugger or logging to see what? FireBug is also tremendously helpful for this: http://www.getfirebug.com/
Nick Craver
Firebug says my JSON is invalid? I didn't have my [Web Method] static so that explains the server-side problem. Sorry, man I'm new to this stuff..
Matt
@Matt - You fix the server-side, still an issue? If so update and we'll see what the problem is.
Nick Craver