Force jQuery.load() to POST when using jQuery.param()
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.
精彩评论