jquery - Unable to send JSON data to server from javascript -


i need send json data server method.

this method works when pass simple 'test' string, not 1 follows:

function sendtoserver() {     $.ajax({         type: "post",         url: "default.aspx/saveclientgrid",         data: "{ griddata: 'test' }",         contenttype: "application/json; charset=utf-8",         datatype: "json"     }); } 

doesn't work:

function sendtoserver() {     var data = json.stringify(datasource);     $.ajax({         type: "post",         url: "default.aspx/saveclientgrid",         data: "{ griddata: " + data + " }",         contenttype: "application/json; charset=utf-8",         datatype: "json"     }); } 

figured it, 1 works:

function sendtoserver() {     var data = json.stringify(datasource);     $.ajax({         type: "post",         url: "default.aspx/saveclientgrid",         data: "{ griddata: '" + data + "' }",         contenttype: "application/json; charset=utf-8",         datatype: "json"     }); } 

i had add single quotes around data -

 data: "{ griddata: '" + data + "' }" 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -