how to dynamically change the url ajax?

how to dynamically change the url ajax?

Law004Law004 Posts: 10Questions: 1Answers: 0
edited November 2015 in Free community support

I want to call a hyperlink in a modal window, the problem is that I can not recall the date variable + data + into the " #example00" "url" , Please Help !!

    <script type="text/javascript">
    $(document).ready(function () {
    $('#example').DataTable( {
            "ajax": {
            "url": "http://192.168.6.251:3000/clienti",
            "dataSrc": ""
              },
              
              prerender:true,
              
            "language": {
            "url": "https://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Italian.json"
              },
              
                dom: 'Bfrtip',
        buttons: [
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ],        
              
              "columns": [
        { "data": "COD_CF",
        "render": function(data, type, full, meta) {        
                 return '<a id="'+ data +'" href="'+ data +'" data-toggle="modal" data-target="#myModal" >' + data + '</a>';  
                  
            }
        },
        
            { "data": "Denominazione"},
            { "data": "Tel" },
            { "data": "Email" },
            { "data": "Indirizzo" },
            { "data": "Comune" },
            { "data": "PROV" },
            { "data": "CAP" },
            { "data": "P_IVa" } 
        ]
    });
    

    
     $('#example00').DataTable( {
            "ajax": {
            "url": "http://192.168.6.251:3000/listaddtIN?codiceCliente=  I want THE VARIABLE + date + HERE ",
            "dataSrc": ""
              },

               prerender:true,
                           
            "language": {
            "url": "https://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Italian.json"
              },
              
                  dom: 'Bfrtip',
        buttons: [
            'excelHtml5',
            'csvHtml5',
            'pdfHtml5'
        ],
              
            "columns": [
            { "data": "DOC_ID" },
             { "data": "ANNO_DOC" },
              { "data": "NUM_DOC" }
            //      { "data": new Date("DATA_DOC").getDate()}
        ]
    });
    
    
});
    </script>

Answers

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75
  • Law004Law004 Posts: 10Questions: 1Answers: 0

    hi thanks for the reply I have already tested this feature and does not work :-(

  • Law004Law004 Posts: 10Questions: 1Answers: 0
    edited November 2015

    I tried this feature but it does not work ...


    <script type="text/javascript"> var table; $(document).ready(function() { $('#example').DataTable( { "ajax": { "url": "http://192.168.6.251:3000/clienti", "dataSrc": "" }, prerender:true, "language": { "url": "https://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Italian.json" }, dom: 'Bfrtip', buttons: [ 'excelHtml5', 'csvHtml5', 'pdfHtml5' ], "columns": [ { "data": "COD_CF", "render": function(data, type, full, meta) { var newUrl = 'http://192.168.6.251:3000/listaddtIN?codiceCliente=' + data; return '<a onclick="table.ajax.url(newUrl).load();" id="'+ data +'" href="'+ data +'" data-toggle="modal" data-target="#myModal" >' + data + '</a>'; } }, { "data": "Denominazione"}, { "data": "Tel" }, { "data": "Email" }, { "data": "Indirizzo" }, { "data": "Comune" }, { "data": "PROV" }, { "data": "CAP" }, { "data": "P_IVa" }, ] }); table = $('#example00').DataTable({ "ajax": { "url": "http://192.168.6.251:3000/listaddtIN?codiceCliente=003205", "dataSrc": "" }, prerender:true, "language": { "url": "https://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Italian.json" }, dom: 'Bfrtip', buttons: [ 'excelHtml5', 'csvHtml5', 'pdfHtml5' ], "columns": [ { "data": "DOC_ID" }, { "data": "ANNO_DOC" }, { "data": "NUM_DOC" } // { "data": new Date("DATA_DOC").getDate()} ] }); }); </script>
  • Law004Law004 Posts: 10Questions: 1Answers: 0

    I get a message that says INVALID JSON response !!!

  • ThomDThomD Posts: 334Questions: 11Answers: 43

    Did you inspect that rendered <a> to be sure the code is clean? Is the onclick firing?

  • Law004Law004 Posts: 10Questions: 1Answers: 0

    I also checked the " "

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    Oh wait, so in the two different JSON responses, is the structure different as well? I notice the columns is different between the two tables, so if its different, thats an issue. Youd need to destroy and recreate the entire table

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    Oh, you want data to go with the ajax request? You can use ajax.data

  • Law004Law004 Posts: 10Questions: 1Answers: 0

    sure tables are different, they also have two different id they are example and example00

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    Oh then nevermind, I thought you were reloading hte same table.

    if you need to pass data with the ajax req, just use ajax.data

  • Law004Law004 Posts: 10Questions: 1Answers: 0
    edited November 2015

    I'm trying not work

  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    Im honestly not sure what you just tried to ask..

  • Law004Law004 Posts: 10Questions: 1Answers: 0

    I'm trying not work



    <script type="text/javascript"> var table; $('#example').DataTable( { "ajax": { "url": "http://192.168.6.251:3000/clienti", "dataSrc": "" }, prerender:true, "language": { "url": "https://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Italian.json" }, dom: 'Bfrtip', buttons: [ 'excelHtml5', 'csvHtml5', 'pdfHtml5' ], "columns": [ { "data": "COD_CF", "render": function(data, type, full, meta) { return '<a onclick="table.ajax.data({"codiceCliente" : ' + data + '}).load();" href="'+ data +'" data-toggle="modal" data-target="#myModal" >' + data + '</a>'; } }, { "data": "Denominazione"}, { "data": "Tel" }, { "data": "Email" }, { "data": "Indirizzo" }, { "data": "Comune" }, { "data": "PROV" }, { "data": "CAP" }, { "data": "P_IVa" }, ] }); table = $('#example00').DataTable( { "ajax": { "url": "http://192.168.6.251:3000/listaddtIN", "contentType": "application/json", "type": "POST", "data": { "codiceCliente":"003205", } }, prerender:true, "language": { "url": "https://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Italian.json" }, dom: 'Bfrtip', buttons: [ 'excelHtml5', 'csvHtml5', 'pdfHtml5' ], "columns": [ { "data": "DOC_ID" }, { "data": "ANNO_DOC" }, { "data": "NUM_DOC" } // { "data": new Date("DATA_DOC").getDate()} ] }); }); </script>
  • jLinuxjLinux Posts: 981Questions: 73Answers: 75

    Why doesnt it work? what error do you get? any logs in the console?

    Need details man.. make it easy for us to help you..

  • Law004Law004 Posts: 10Questions: 1Answers: 0

    don't call the json, when I click on the link to show the new table into the modal window #MyModal, it loading ... , and can not find the json.....

  • Law004Law004 Posts: 10Questions: 1Answers: 0

    I tried the first example of the links that I you posted, and unfortunately does not work

This discussion has been closed.