且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用MagicSuggest将变量发送到服务器

更新时间:2023-01-17 10:51:19

您需要为您的配置添加名称属性:

  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
});
});

,您应该检索$ _POST ['ms1']中的值,该值实际上是一个数组

如果你需要城市名称而不是城市ID,你可以在配置属性中指定valueField并将其设置为'name' ,像这样:

  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
});
});

这样组件将使用名称作为ID而不是ID本身。



如果您因为任何原因需要ID和名称,则可以使用beforeload事件来设置其他自定义POST参数。


Im using this great jquery plugin to handle autocomplete on textboxes, i got everything working using this script:

        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,
                allowFreeEntries: false,
                selectionPosition: 'right',
                groupBy: 'utenti',
                maxDropHeight: 200
            });
        });

And this Html:

<form name="email_form">
  <input id="test_normalValue" name="test_normalValue" type="text" class="input-large">
  <input id="ms1" name="ms1" type="text" class="input-large">
</form>

But when i POST or GET the form no value is sended, just the test_normalValue. Does anybody encounter this problem too?

PS: According to this thread this functionality is present since 1.1.2 (im using 1.2.3)

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.