JQuery提交JSON string資料

來源:互聯網
上載者:User

標籤:jquery   json   

$("#btnSend").click(function() {

    $("#request-process-patent").html("正在提交資料,請勿關閉當前視窗...");

    $.ajax({

        type: "POST",

        url: "RequestData.ashx",

        contentType: "application/json; charset=utf-8",

        data: JSON.stringify(GetJsonData()),

        dataType: "json",

        success: function (message) {

            if (message > 0) {

                alert("請求已提交!我們會儘快與您取得聯絡");

            }

        },

        error: function (message) {

            $("#request-process-patent").html("提交資料失敗!");

        }

    });

});


function GetJsonData() {

    var json = {

        "classid": 2,

        "name": $("#tb_name").val(),

        "zlclass": "測試類型1,測試類型2,測試類型3",

        "pname": $("#tb_contact_people").val(),

        "tel": $("#tb_contact_phone").val()

    };

    return json;

}


核心為JSON.stringify()方法,方法說明:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify


參考文章:http://www.cnblogs.com/jaxu/p/3698404.html

本文出自 “java程式猿的部落格” 部落格,請務必保留此出處http://chengxuyuan.blog.51cto.com/5789198/1864856

JQuery提交JSON string資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.