how can i do multiple Ajax call?

how can i do multiple Ajax call?

roybaroyba Posts: 5Questions: 3Answers: 0

Hi,

I added a 'filter results' button and i want to update the table each time the filter button is clicked.

How can i integrate to "on click" event to the Ajax request? i've tried to simply add a new request - but i get no response. the only response i get is only when i do a external Ajax request... but then the table won't update..

Thanks

Answers

  • bazianmbazianm Posts: 10Questions: 5Answers: 0

    Is your table bound to an ajax call? If yes, couldn't you send the filter off to the server and then just .reload()? The .reload() will reissue the ajax call and repopulate the table...

  • roybaroyba Posts: 5Questions: 3Answers: 0
    edited August 2016

    Hi, the first table (#campaigns) is bound, and works well, i added a select menu (.selectpicker) which should do a filter results to the #campaigns table. Now, where and how should i add the Ajax request? (kind of newbie)... thanks

    Here is my code :

    script.
            $(function () {
                var tableTest = $('#campaigns').dataTable({
                    "ajax": {
                        "url": "/Marketing/banner_stats/"+#{campaign_id},
                        "dataSrc": "result"
                    },
                    "columns": [
                        {"data": "Advertiser"},
                        {"data": "Campaign"},
                        {"data": "Banner"},
                        {"data": "Impressions"},
                        {"data": "Clicks"},
                        {"data": "CTR"}
                    ],
                    "columnDefs": [
                        {
                            "render": function (data, type, row) {
                                if (data.indexOf("(Deleted)")){
                                    data = data.replace("(Deleted)", "<span class='label label-danger'>Deleted</span>");
                                }
                                return data;
                            },
                            "targets": 0
                        },
                        {
                            "render": function (data, type, row) {
                                if (data.indexOf("(Deleted)")) {
                                    data = data.replace("(Deleted)", "<span class='label label-danger'>Deleted</span>");
                                }
                                return data;
                            },
                            "targets": 1
                        },
                        {
                            "render": function (data, type, row) {
                                if (data.indexOf("(Deleted)")) {
                                    data = data.replace("(Deleted)", "<span class='label label-danger'>Deleted</span>");
                                }
                                return data;
                            },
                            "targets": 2
                        },
                    ]
                });
    
                $(".selectpicker").on('change', function () {
    
    
                   //Ajax request
    
    
                     //tableTest.ajax.url( "/Marketing/get_campaigns/"+range).load();
    
    
                });
    
    
            });
    
    
  • bazianmbazianm Posts: 10Questions: 5Answers: 0

    How about just adding it as a query string to the ajax url?

This discussion has been closed.