javascript - Server does not receive data from ajax call -
i have problem. i'm trying send content of textarea ajax call, doesn't seem working, , don't know why.
there's method called getstatus(string statustext)
need receive content.
here's javascript code:
$("#btnsavestatus").on("click", function () { var statustext = $(".textareaedit").val(); $.ajax({ type: "get", url: "default.aspx/getstatus", data: "{statustext:'" + statustext + "'}", contenttype: "application/json; charset=utf-8", datatype: "json", success: function (result) { // $('#littlbioid').text(result.d); } }); });
please advise. should know i'm new web development.
- you can't have request body in request, have use post request that
- the string constrcting not valid json since:
- property names must strings
- you have no idea user enter in textarea - might contain characters special meaning in json
generate json programatically.
{ type: "post", url: "default.aspx/getstatus", data: json.stringify({ statustext: statustext }), // etc
obviously, server side of process needs set accept post request json body (instead of more standard url form encoded format) well.
Comments
Post a Comment