How to execute an ajax call on a url

How to execute an ajax call on a url

islamelshobokshyislamelshobokshy Posts: 82Questions: 17Answers: 1
edited May 18 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: 3,284Questions: 19Answers: 739

    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: 82Questions: 17Answers: 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: 3,284Questions: 19Answers: 739
    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: 82Questions: 17Answers: 1

    It was indeed ajax.dataSrc, thanks !

Sign In or Register to comment.