简体   繁体   中英

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) {
        },
});

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM