admin管理员组

文章数量:1307836

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'.

本文标签: javascriptHow to force jQuery load() method to use POSTStack Overflow