ajax用post模擬提交表單請求&&后台獲取數據方法


JS代碼

function postForm() {
    var data = new FormData();
    var post_data = { "K1": "Va", "K2": "V2", "K3": "V3"};
    data.append("MyParam", JSON.stringify(post_data)); 
    $.ajax({
        type: "post",
        url: "http://localhost:8000/API/MyMethod",        
        contentType: false,
        cache: false,
        currentType: false,
        processData: false,
        data: data,
        success: function (res) { 
            alert("success");
        },
        error: function (xmlHttpRequest, textStatus, errorThrown) {
            alert("error");
        }
    }); 
}

WebApi 接收

string jsoninfo = HttpContext.Current.Request["MyParam"].ToString();

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM