How to pass json string to webmethod c# ASP.NET

后端 未结 2 1919
盖世英雄少女心
盖世英雄少女心 2020-12-20 19:11

Im trying to stringify a javascript object and then pass the string as a parameter to a WebMethod in Code Behind. I can\'t get it to work as I get a Internal Server Error of

2条回答
  •  醉梦人生
    2020-12-20 19:42

    Use this format for ajax post format :

    var jSon = JSON.stringify(javascriptObject);
    

    Your Json Format will be like this : '{name: "' + name +'" }',

    function ShowCurrentTime() {
        $.ajax({
            type: "POST",
            url: "Installningar.aspx/Updatera",
            data: jSon; 
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: OnSuccess,
            failure: function(response) {
                alert(response.d);
            }
        });
    }
    function OnSuccess(response) {
        alert(response.d);
    }
    

    Follow this step for complete run your code : http://www.aspsnippets.com/Articles/Calling-ASPNet-WebMethod-using-jQuery-AJAX.aspx

提交回复
热议问题