How can I get a JSON via URL?

How can I get a JSON via URL?

rafaelmakiyamarafaelmakiyama Posts: 4Questions: 1Answers: 0
edited September 2019 in Free community support

My doubt is. I have one Isset Function in my PHP file.

I want to select this isset to bring me the data
But i dont know how to do this.

Answers

  • allanallan Posts: 61,710Questions: 1Answers: 10,103 Site admin

    You can't via a URL along since your PHP is specifically checking for a POST parameter. You would need to send a POST request!

    Allan

  • rafaelmakiyamarafaelmakiyama Posts: 4Questions: 1Answers: 0

    Allan, so how do I have to do in my PHP? I didnt understand.

  • SchautDollarSchautDollar Posts: 21Questions: 6Answers: 1

    I think what Allan is saying - correct me if I'm wrong is that you need to set the parameter cadastrarEstudante, otherwise the PHP script will never know you need to do something.

    You can set the data manually via the data option.

    More info at https://datatables.net/reference/option/ajax.data

  • rafaelmakiyamarafaelmakiyama Posts: 4Questions: 1Answers: 0
    edited September 2019

    $('#example').dataTable( { "ajax": { "url": "data.json", "contentType": "application/json", "type": "POST", "data": function ( d ) { return JSON.stringify( d ); } } } );
    In this way?

  • rafaelmakiyamarafaelmakiyama Posts: 4Questions: 1Answers: 0

    in the "data" function i have to pass the parameter "cadastrar estudante"?

  • SchautDollarSchautDollar Posts: 21Questions: 6Answers: 1

    Yes, that's the idea. Although you'd manually set the value like below.

    ajax: {
        url: "<insert your URL>",
        data: function (d) {
            return $.extend({}, d, {
                "cadastrarEstudante": <value>
            });
        },
        type: "POST"
    },
    
  • allanallan Posts: 61,710Questions: 1Answers: 10,103 Site admin

    Spot on I'd say! You could also do:

    data: function (d) {
      d.cadastrarEstudante = <value>;
    }
    

    which in this context gives the same result.

    Allan

This discussion has been closed.