How can I use JQuery to post JSON data?

后端 未结 5 2060
无人及你
无人及你 2020-11-22 07:46

I would like to post Json to a web service on the same server. But I don\'t know how to post Json using JQuery. I have tried with this code:

$.ajax({
    typ         


        
5条回答
  •  长发绾君心
    2020-11-22 08:22

    I tried Ninh Pham's solution but it didn't work for me until I tweaked it - see below. Remove contentType and don't encode your json data

    $.fn.postJSON = function(url, data) {
        return $.ajax({
                type: 'POST',
                url: url,
                data: data,
                dataType: 'json'
            });
    

提交回复
热议问题