How to use getJSON, sending data with post method?

后端 未结 7 1003
暗喜
暗喜 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条回答
  •  -上瘾入骨i
    2020-11-29 18:31

    $.getJSON() is pretty handy for sending an AJAX request and getting back JSON data as a response. Alas, the jQuery documentation lacks a sister function that should be named $.postJSON(). Why not just use $.getJSON() and be done with it? Well, perhaps you want to send a large amount of data or, in my case, IE7 just doesn’t want to work properly with a GET request.

    It is true, there is currently no $.postJSON() method, but you can accomplish the same thing by specifying a fourth parameter (type) in the $.post() function:

    My code looked like this:

    $.post('script.php', data, function(response) {
      // Do something with the request
    }, 'json');
    

提交回复
热议问题