【问题标题】:How to add a body to the ajax request of select 2?如何在select 2的ajax请求中添加body?
【发布时间】:2018-08-09 22:09:28
【问题描述】:

我想使用 Select2 框模仿正文类型为纯文本(例如“从表中选择 *”)的 URL 的帖子,但是我在哪里定义要发布的正文?

$("#sales_ids").select2({
        placeholder: "Select your Partners",
        multiple: 'multiple',
        ajax: {
            url: 'http://www.google.com/,
            dataType: 'json',
            type: 'post',
            multiple: 'multiple',
            allowclear: 'true',


            processResults: function p(data){

                var mapped = $.map(data, function(obj) {
                    obj.text = obj.text || obj.name;
                    obj.id = obj.id || obj.salesId;
                    return obj;



                })

                return { 
                    results: mapped
                }

【问题讨论】:

    标签: drop-down-menu jquery-selectors jquery-select2


    【解决方案1】:
     $.ajax({
        url: 'URL',
        type: 'POST',
        dataType: 'json',
        async: false,
    
        // Data Goes Here
        data: 'select * from table'
        contentType: 'test/plain'
    
        success: function (data, textStatus, xhr) {
        // Success Code
        },
        error: function (xhr, textStatus, errorThrown) {
            console.log('Error in Database');
        }
    });
    

    【讨论】:

    • 如果我想让纯文本“select * from table”出现在帖子的正文中,这个字符串在哪里输入?你说'数据在这里',我是否输入数据:“从表中选择 *”?
    • @perry 请查看我编辑的答案。希望这能回答你的问题。
    • 非常感谢!我仍然有空的结果,但我得到了我需要的。
    • 很高兴我的回答对您有所帮助。如果觉得可以,请投票。@perry
    猜你喜欢
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    • 1970-01-01
    • 2018-02-09
    • 1970-01-01
    • 2017-06-15
    • 2021-07-23
    • 1970-01-01
    相关资源
    最近更新 更多