ajax post works but data not transferred

ajax post works but data not transferred

cachiapcachiap Posts: 40Questions: 5Answers: 0
edited July 2017 in Buttons

I have used this method before but for some reason it is not working on this page and I am not sure what the problems is.

If I post an actual integer value the data is sent to the page without any problems. I can see this using the firebug app. and the post is there and being sent to the correct page. However this will not take place when I ask it to send the data ['pdflocation.pdf_id']. This data is there since, again, it shows up in the XHR RESPONSE in Firebug.

Here is a sample of the XHR response I see with the data:

{"DT_RowId":"row_28224","pdflocation":{"pdflocid":"28224","locid":"7","pdf_id":"8875","prodname"
:"3M Brand Fire Barrier CP-25 WB+ Formulation B (09-5540-1)","prodidentifier":"156, Plant","prodtype"
:"Adhesive","ref4":"","ref5":""},"product_name":{"pdfprodname":"3M Brand Fire Barrier CP-25 WB+ Formulation
 B (09-5540-1)","pdffilename":"150509PU002.pdf","pdfmanufacturer":"3M Canada Company","pdfcasno":"12447-61-9
 1344-09-8 1241-94- 1309-37-1","pdfeffectdate":"2006-08-01","pdfexpiredate":"9999-12-31","pdfstatus"
:"Y","pdfcontrolled":"N"}}

As I mentioned, I have used this method to post before and it has worked without a problem. I am wondering if the problem lies with the "dot" term in the data ['pdflocation.pdf_id'] term I'm using? I have to use this as this data is the result of a join between two tables (product_name and pdflocation). The Delete button is where this problem is occuring. The button appears at the end of each row of the table and when DELETE is clicked I want the item removed from the pdflocation table and itemized on a second table that records this for future reference. The index I am sending to the serverside is crucial for this to be tracked.

This is only part of the page since it is long and think this is the essential part pertaining to this question. Any advice would be really appreciated.

    var table = $('#table_products').DataTable( {
        
        ajax: {
    
        url: "./serverSideEditLocation2_data.php",
        
        type: "post",
        
            "data": {
                      "locid": <?php echo $locid ?>
             }

         },

         "serverSide": true,
         
         "processing": true,
         
         "deferRender": true,
        
        
         "lengthMenu": [[100, 1, 5, 10, 25, 50, 75, -1],[100, 1, 5, 10, 25, 50, 75, "ALL"] ],
         
     
         "pagingType": "full_numbers",           
    
  //This block sets the scrolling function and table display length  
    

        "scrollY": "300px",
        
        "scrollCollapse": true,

        
        "dom": '<B"clear"f>irt<"bottom"p><"clear">',
        
        
        
        
        
        columns: [ 
                        { data: null, defaultContent: '', orderable: false, searchable: false, target: 0 },

                        { data: "pdflocation.pdf_id",  target: 1 },
                        { data: "product_name.pdfprodname", target: 2 },
                        { data: "product_name.pdfmanufacturer", target: 3 },
                        { data: "product_name.pdfcasno", target: 4 },
                        { data: "product_name.pdfeffectdate", target: 5 },



                        { data: "pdflocation.prodname", target: 6 },
                        { data: "pdflocation.prodidentifier", target: 7 },
            { data: "pdflocation.prodtype", target: 8 },
            { data: "pdflocation.ref4", target: 9 },                        
                        { data: "pdflocation.ref5", target: 10 },
                         
                        { data: "product_name.pdfexpiredate", target: 11},
                        { data: "product_name.pdfcontrolled", target: 12 },
                        { data: null, defaultContent: '<button class="delete" style="border:1px solid #666;\n\
                                font-size:12px;\n\
                                font-weight:bold;\n\
                                cursor: pointer;\n\
                                  -webkit-border-radius: 2px;\n\
                           -moz-border-radius: 2px;\n\
                            -ms-border-radius: 2px;\n\
                             -o-border-radius: 2px;\n\
                                border-radius: 2px;\n\
                                   text-decoration: none !important;\n\
                                  -webkit-box-shadow: 1px 1px 3px #999;\n\
                           -moz-box-shadow: 1px 1px 3px #999;\n\
                            -ms-box-shadow: 1px 1px 3px #999;\n\
                             -o-box-shadow: 1px 1px 3px #999;\n\
                           box-shadow: 1px 1px 3px #999;\n\
                               background: orange;">DELETE</button>', orderable: false, searchable: false, target: 13 }

        ],
                
        order: [[ 2, 'asc' ], [3, 'asc']],

// Removed the ColDefs to shorten post

 $('#table_products').on( 'click', 'button.delete', function () {
                          var data = table.row( $(this).parents('tr') ).data();


                          var r = confirm("ALERT:\n\you are about to DELETE this entry");

                          if (r==true){

                          $.ajax({

                                    "url":"./deleteItem_clientLocation.php",
                                    "type": "post",
                                    
                                    data:{

                                       "pdfID": data['pdflocation.pdf_id']

                                    }
                                    
                                   });
                                   

                            table.draw();      



                        } 


                        });

This question has accepted answers - jump to:

Answers

  • allanallan Posts: 61,452Questions: 1Answers: 10,055 Site admin
    Answer ✓

    Hi,

    You can't use serverSide with a plain array of data. It doesn't contain enough information to be able to contain the server-side processing parameters that DataTables requires.

    I would suggest you drop that option and use ajax.dataSrc set to be an empty string to tell DataTables to expect a flat array. See this example.

    Allan

  • cachiapcachiap Posts: 40Questions: 5Answers: 0

    Thanks Allan. I am working through your suggestions.

  • cachiapcachiap Posts: 40Questions: 5Answers: 0

    Allan, worked on this and here is the solution I found to extract the data from cell [1] and pass it to my php page as the variable pdfID. It works well.

                $('#table_products').on( 'click', 'button.delete', function () {
                    
    
    
                              var r = confirm("ALERT:\n\you are about to DELETE this entry");
    
                              if (r==true){
                                  
                                  
    
                              $.ajax({
    
                                        "url":"./deleteItem_clientLocation.php",
                                        "type": "post", 
                                        
                                        data:{
    
                                           "pdfID": this.parentNode.parentNode.cells[1].textContent,
                                           "locid": <?php echo $locid ?>
    
                                        }
                                        
                                       });
                                       
    
                                table.draw();      
    
    
    
                            } 
    
    
                            });
    
    
  • allanallan Posts: 61,452Questions: 1Answers: 10,055 Site admin
    Answer ✓

    Thanks for posting back - great to hear you've go it working.

    Allan

This discussion has been closed.