DataTable not getting data from backend

DataTable not getting data from backend

azulahimeazulahime Posts: 6Questions: 3Answers: 1
edited October 2022 in Free community support

Hi, I would like to ask for help with a problem I'm currently having with my django project using a server-side datatable. Despite getting results when I go to this URL 'http://IP/sctagging/json/', when loading the datatable, I got the error:
Failed to load resource: the server responded with a status of 404 (Not Found)

Please refer to a sample of the data found in the URL:

[{"idh": "sample", "plant": "sample", "company_code": "sample", "company_country": "AU", "company_name": "sample", "plant_country": "AU", "plant_name": "sample", "maketostrategy": "sample", "valclass": "sample", "idh_desc": "sample"}]

Please refer to my DataTable code below:

var vSelectedTags = JSON.parse('{{jsontags}}');
var columndata = []; 
var vLength = vSelectedTags.length; 
for(x=0; x<vLength; x++){
   var vNewColumn = {"data":vSelectedTags[x]}
   columndata.push(vNewColumn);
}

        
var table = $('#example').DataTable( {
      "initComplete": function(settings, json) {
         table.buttons().container()
          .appendTo( $('div.column.is-half', table.table().container()).eq(0) );
          alert( 'All Data has been loaded into the table successfully. To view and filter all generated records, please download the excel file by clicking on the excel button.' );
        },
        scrollX: true,
        scrollY: "500px",
        lengthChange: false,
        pageLength:5000, 
        buttons: [ 'excel' ],
        processing: true,
        serverSide: true,
        ajax: {
            url: 'http://IP/sctagging/json/',
  
        },
        columns: columndata,
})

Please refer to my django view function below:

def MaterialTagging_JSON(request):
    vLatestUpdateDate = ScTaggingLargeTableIp.objects.values('update_date').order_by('-update_date')[:1]
    if 'idhstatus' in request.session:
            vSelectedCountries = request.session['selectedcountries'] 
            vSelectedPlants =request.session['selectedplants'] 
            vSelectedValClass = request.session['selectedvalclass'] 
            vSelectedCoCode = request.session['selectedcocode'] 
            vSelectedCompanyCountry = request.session['selectedcompanycountry']
            vSelectedCoName = request.session['selectedconame']
            columns = request.session['selectedtags']
            vQuery = list(ScTaggingLargeTableIp.objects.values(*columns).filter(update_date = vLatestUpdateDate,plant_country__in=(vSelectedCountries), plant__in=(vSelectedPlants), valclass__in=(vSelectedValClass), company_country__in=(vSelectedCompanyCountry),  company_code__in=(vSelectedCoCode), company_name__in=(vSelectedCoName)))
            response = mark_safe(json.dumps(vQuery,cls=DecimalEncoder))
            return HttpResponse(response, content_type='application/json')

Answers

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    404 means something was found on the server - if you check the browser's console you'll be able to see what it was looking for, and then you can verify that against the server logs to see if there's an issue.

    Colin

  • kthorngrenkthorngren Posts: 21,330Questions: 26Answers: 4,951

    In addition to looking at the server logs that Colin mentioned (which you need to fix first) your JSON data example does not conform to the expected server side processing protocol. You don't need to enable server side processing to use ajax loaded data. More info about server side processing here.

    Kevin

Sign In or Register to comment.