Sending vars to server using MagicSuggest

限于喜欢 提交于 2019-12-06 08:31:35

You need to add a name property to your configuration:

    var ms1;
    $(document).ready(function() {
            ms1 = $('#ms1').magicSuggest({
            data: 'http://punctis.com/app_dev.php/ajax/autocompletefeed/1/city',
            sortOrder: 'name',
            minChars: 2,
            maxResults: false,
            name: 'ms1',
            allowFreeEntries: false,
            selectionPosition: 'right',
            groupBy: 'utenti',
            maxDropHeight: 200
        });
    });

and you should retrieve the value in $_POST['ms1'], which will actually be an array of city ids.

[EDIT] If you need the city names instead of the city IDs, you can specify the valueField in your configuration property and set it to 'name', like this:

    var ms1;
    $(document).ready(function() {
            ms1 = $('#ms1').magicSuggest({
            data: 'http://punctis.com/app_dev.php/ajax/autocompletefeed/1/city',
            sortOrder: 'name',
            valueField: 'name',
            minChars: 2,
            maxResults: false,
            name: 'ms1',
            allowFreeEntries: false,
            selectionPosition: 'right',
            groupBy: 'utenti',
            maxDropHeight: 200
        });
    });

That way the component will use the names as IDs instead of the ids themselves.

If you need both the IDs and the names for whatever reason, you can use the beforeload event to set additional custom POST parameters.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!