Haris ur Rehman
Haris ur Rehman

Reputation: 2663

jQuery - Ajax POST request converted to GET request

I am trying to POST json data via ajax. The json data contains a large html table. However, this POST request is converted to GET request and I get Error 414 (Request-URI too long). I know jsonp POST requests are converted to GET, but why my json request is converted to GET?

$.ajax({
        url: 'api.php',
        method: 'POST',
        data: {
            'call': 'emailSalesReportToAdmin',
            'tableHtml': $('#tblSalesReport').parent().html()
        },
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (response) {
        },
});

Upvotes: 1

Views: 1203

Answers (2)

Santosh Sawant
Santosh Sawant

Reputation: 275

Yes , for older version, please use type:'POST' instead of method:'POST'

As mentioned on jQuery documentation

type (default: 'GET') Type: String An alias for method. You should use type if you're using versions of jQuery prior to 1.9.0.

Upvotes: 2

Haris ur Rehman
Haris ur Rehman

Reputation: 2663

I found the issue and it was an older version of jQuery. The above code worked fine in jQuery version 1.12.

Upvotes: 0

Related Questions