How to execute an ajax call on a url

How to execute an ajax call on a url

islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1
edited May 2018 in Free community support

I'm trying to execute an ajax call on a URL https://site.com/api/X/Y and not on a json file, the api does return a json formated file. How can I do so using the datatables ajax method?

ajax: {
    url: "<?php echo $url?>",
    type: "GET"
},

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945

    What are you using for your server code?

    Its up to the server code to encode the data result into a JSON string before returning the result.

    Kevin

  • islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1

    @kthorngren I'm just trying to get the json of an API. As if I would use :

    $.ajax({
      dataType: 'json',
      url: url,
      data: data,
      success: success
    });
    
  • kthorngrenkthorngren Posts: 21,299Questions: 26Answers: 4,945
    Answer ✓

    Sorry, I misread your original description. What is returned when you use the ajax option?

    Datatables basically passes your ajax config to the jQuery ajax method. However Datatables has it's own option called ajax.dataSrc used to extract data if not in the expected data object. Maybe you need to use ajax.dataSrc to tell Datatables where the data is.

    Kevin

  • islamelshobokshyislamelshobokshy Posts: 99Questions: 20Answers: 1

    It was indeed ajax.dataSrc, thanks !

This discussion has been closed.