jquery - How to get JSON POST data in ASP.NET Web Forms? -
i have jquery posting data onto 1 of web pages.
right i'm trying post json test out, can't figure out have data in back-end once it's posted.
i've used request.params
posted data, doesn't seem working time.
this code i'm using post:
// data testing purposes, doesn't var person = { name: "bob", address: "123 main st.", phone: "555-5555" } var jqxhr = $.ajax({ type: "post", url: "/example/mypage.aspx", contenttype: 'application/json; charset=utf-8', datatype: "json", timeout: 0, success: function () { alert("success"); }, error: function (xhr, status, error) { alert(error); }, data: person });
the post successful though, can see using fiddler, plus when check request.contentlength
returns right number of bytes posted.
but can't find actual data anywhere. ideas on i'm doing wrong?
thanks in advance.
posting javascript object:
- pass plain object data option,
- leave contenttype option alone. default option perfect.
then can access property values of object in request collection if have posted form.
server side:
string input; using(var reader = new streamreader(request.inputstream)){ input = reader.readtoend(); }
posting json:
- data: json.stringify(person),
- contenttype: "application/json"
server side:
string json; using(var reader = new streamreader(request.inputstream)){ json = reader.readtoend(); } var person = json.decode(json);
referenced from: http://www.mikesdotnetting.com/article/220/posting-data-with-jquery-ajax-in-asp-net-razor-web-pages
Comments
Post a Comment