开发者

Force jQuery.load() to POST when using jQuery.param()

开发者 https://www.devze.com 2023-02-15 00:29 出处:网络
Ok, so .load() uses... The POST method is used if data is provided as an object; otherwise, GET is assumed.

Ok, so .load() uses...

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

I have the following...

// an array of itemIds
var items = $selected.map(function() {
   return $(this).find('.item').text();
}).get();

// post the data
$container.load(
    _url,
    $.param(data, true),
    function(response, status, xhr) {
        //...
    }
);

The problem I have is that if I use $.param to serialise the data, it seems that GET is used.

If I don't use $.param then POST is used but I run into the problem again with the array not being serialised correctly and I don't receive the data in my controller.

Is there an easy way around t开发者_如何学运维his?


You can use jQuery.get() instead of .load():

$.get(_url, $.param(data, true), function(data) {
  $container.html(data);
});

This will have the same effect as a call to load with parameters, but with a GET request instead of a POST request.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号