How to use getJSON, sending data with post method?

后端 未结 7 1008
暗喜
暗喜 2020-11-29 17:45

I am using above method & it works well with one parameter in URL.

e.g. Students/getstud/1 where controller/action/parameter format is applied.

7条回答
  •  渐次进展
    2020-11-29 18:32

    The $.getJSON() method does an HTTP GET and not POST. You need to use $.post()

    $.post(url, dataToBeSent, function(data, textStatus) {
      //data contains the JSON object
      //textStatus contains the status: success, error, etc
    }, "json");
    

    In that call, dataToBeSent could be anything you want, although if are sending the contents of a an html form, you can use the serialize method to create the data for the POST from your form.

    var dataToBeSent = $("form").serialize();
    

提交回复
热议问题