Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 82540

select2 box with multiple selections

$
0
0

I added the following reply to select2 box with dynamic url but it really deserves it's own question. Can this be fixed?

I've hit another issue when using ajax and multiple: true with the select2 plugin. The code in beforeSend passes the array value as a delimited string.

// Add an initial data request to the server, but don't
// override `data` since the dev might be using that
var initData = 'initialValue=true&value='+
    JSON.stringify(val);

That produces a url like http://localhost/api/Lookup?initialValue=true&value=["1","12"] which isn't ideal.

A better way would be to use the jQuery.param() function instead.

// Add an initial data request to the server, but don't
// override `data` since the dev might be using that
var initData = $.param({ initialValue: true, value: val }, true);

That produces a url like http://localhost/api/Lookup?initialValue=true&value=1&value=12 which is easier to work with.


Viewing all articles
Browse latest Browse all 82540

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>