浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

MVC3, jQuery and JSON.stringify : The Official Microsoft ASP.NET Forums

MVC3, jQuery and JSON.stringify

 

RSS

6 replies

 

Last post Feb 07, 2012 03:14 AM by atnoslen

  • atnoslen

    atnoslen

    Member

    7 Points

    13 Posts

     

    MVC3, jQuery and JSON.stringify

    Feb 06, 2012 05:45 PM|LINK

    I ran into an issue with JSON.stringify() when trying to use $.getJSON().  Examine this stack overflow discussion, http://stackoverflow.com/questions/9162359/mvc3-controller-null-parameter-using-json-stringify/9164417#9164417

    Breakdown,

    When using $.getJSON() or any $.ajax call with a GET request and using JSON.stringify(), the parameters are null.  This works fine with a HTTP POST, but not with a GET.  Notice where

    $.getJSON('/', JSON.stringify({id:"test"}));

    will result in GET http://localhost?{%22id%22:%22test%22} HTTP/1.1

    while

    $.getJSON('/', {id:"test"});

    results in GET http://localhost/?id=test HTTP/1.1

    Note that the following DOES work.

    $.getJSON('/', { "id": "test" });

    To drive the topic home, this DOES NOT work.

    $.getJSON('/', '{ "id": "test" }');

    I have resorted to using POST to make ajax json calls.  If this is not the proper place to submit bugs or discussion, my apologies.

    Noslen

posted on 2012-05-11 11:02  lexus  阅读(590)  评论(0编辑  收藏  举报