使用MagicSuggest将变量发送到服务器 [英] Sending vars to server using MagicSuggest

查看:436
本文介绍了使用MagicSuggest将变量发送到服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用这个伟大的jquery插件来处理文本框上的自动完成,我使用这个脚本得到了一切工作:

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

而这个Html:

 < form name =email_form> 
< input id =test_normalValuename =test_normalValuetype =textclass =input-large>
< input id =ms1name =ms1type =textclass =input-large>
< / form>

但是,当我POST或GET表单没有值发送,只是test_normalValue。有人也遇到这个问题吗?



PS:根据此线程此功能自1.1.2(即时使用1.2.3)开始存在

解决方案

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

  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.

这篇关于使用MagicSuggest将变量发送到服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆