1. 程式人生 > >Ajax提交json字串給後臺處理

Ajax提交json字串給後臺處理

前臺關鍵程式碼

 function save() {
        var imgStr = getImgStr();
        var positionObj = getPositionObj();

        if (positionObj != null) {
            var paramObj = getParamObj();
            var userObj = getUserObj();

            if (paramObj != null) {
                var obj = { "positionObj"
: positionObj, "paramObj": paramObj, "userObj": userObj, "imgStr": imgStr }; $.ajax({ type: "post", url: "/Company/Project/ProcessAdd", contentType: "application/json; charset=utf-8", data: JSON.stringify(obj), dataType: "json"
, success: function (message) { if (message > 0) { alert("請求已提交!我們會盡快與您取得聯絡"); } }, error: function (message) { alert("提交資料失敗!"); } }); } } }

後臺關鍵程式碼

public ActionResult ProcessAdd()
{

    var sr = new StreamReader(Request.InputStream);
    var str = sr.ReadToEnd();

    var json = DynamicJson.Parse(str);

    //.....處理業務

    //返回 跳轉
    return null;
}