最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to force jQuery .load() method to use POST - Stack Overflow

programmeradmin0浏览0评论

Why isn't my method posting data? According to jquery docs: "Request Method

The POST method is used if data is provided as an object; otherwise, GET is assumed."

var car = {{ car }}
var motorcycle = {{ motorcycle }}    
$('.send_data').on('click', function(e){
        e.preventDefault();
        $('#'+container).load(
            $(this).attr('href'),
            { car: car, motorcycle: motorcycle },
            function(data) {
                $('#'+container).effect('highlight');
            }
        );
    })

Why isn't my method posting data? According to jquery docs: "Request Method

The POST method is used if data is provided as an object; otherwise, GET is assumed."

var car = {{ car }}
var motorcycle = {{ motorcycle }}    
$('.send_data').on('click', function(e){
        e.preventDefault();
        $('#'+container).load(
            $(this).attr('href'),
            { car: car, motorcycle: motorcycle },
            function(data) {
                $('#'+container).effect('highlight');
            }
        );
    })
Share Improve this question asked May 21, 2014 at 13:34 CapuchinCapuchin 3,7856 gold badges31 silver badges41 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 7

Use $.post() instead of $.load()

The jQuery .load source code is straightforward:

} else if ( params && typeof params === "object" ) {
    type = "POST";
}

Unless car or motorcycle are not being classified as objects, a POST request should have been issued.

Use $.ajax() and define type: 'post'.

发布评论

评论列表(0)

  1. 暂无评论