-1

我在用

$.ajax({
        url: "http://twitter.com/status/user_timeline/treason.json?count=10&callback=?",

        success: function (data, textStatus, jqXHR) {
                        },
        error: function (jqXHR, textStatus, errorThrown) {
        },
        dataType: "jsonp"
 });

我怎么知道它使用的是 GET 还是 POST?

4

2 回答 2

4

默认情况下它是GET

您可以通过指定类型参数值来覆盖它。

$.ajax({
         url: "someurl",
         type:"POST"
      });

您还可以在方法中全局设置它,$.ajaxSetup以便所有 ajax 调用都使用该设置,除非覆盖它。

$.ajaxSetup({
  type: 'POST'
});

因此,如果您没有$.ajaxSetup设置它的部分,您的问题的答案是GET

于 2012-08-17T23:37:59.547 回答
0

That's really simply, as the dataType is set to JSONP, and JSONP and cross domain requests inserts a script tag in the page to get the data, and as such it ONLY supports GET requests. POST requests aren't possible with a dataType of JSONP, so even if you specify POST as the type, jQuery will always use GET for those kind of Ajax calls, it's not possible to override that "feature".

于 2012-08-17T23:46:30.907 回答