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
Post a Comment