0

Hi my datatables ajax call is as below,

 $(document).ready(function () {

        $('#example').DataTable({
            "ajax": '/api/get_requests'
        });

So I am expecting the call my backend django server as below,

http://localhost:8080/api/get_requests/

But instead it generates an additional random numbers in the end and call is sent as below and my django server says wrong url and gives 404 error

http://localhost:8080/api/get_requests/?_=1511021359038

How can I force the datatables ajax call to not send the additional random numbers

davidkonrad
  • 83,997
  • 17
  • 205
  • 265
Naggappan Ramukannan
  • 2,564
  • 9
  • 36
  • 59
  • are you sure that the ajax is right, by the way why you are hardcoding the URL – mohammedgqudah Nov 18 '17 at 18:48
  • Possible duplicate of [How do I integrate Ajax with Django applications?](https://stackoverflow.com/questions/20306981/how-do-i-integrate-ajax-with-django-applications) – souldeux Nov 18 '17 at 20:22
  • I am not hard coding the IP address (localhost) , URL is the request url which will be handled by django (/api/get_requests/). Now the issue is not with integration. It is sending an extra random number at the end during any request – Naggappan Ramukannan Nov 19 '17 at 03:37

1 Answers1

1

It is not random numbers but a timestamp, the above translates into Sat Nov 18 2017 17:09:19 GMT+0100 (CET).

It is simply how jQuery AJAX cache works, it adds a timestamp to the request to fool the browsers attempt to cache everything. I believe

$('#example').DataTable({
  ajax: {
    cache: false,
    url: '/api/get_requests'
  }
});

will fix the issue.

davidkonrad
  • 83,997
  • 17
  • 205
  • 265