Ajax Get Request

Ajax Get Request

keirlav87keirlav87 Posts: 11Questions: 0Answers: 0
edited June 2012 in General
Hi, I would like to use an ajax datasource but sent to a php script which will return a json object to populate the table with. However I don't want to go through the whole process of using full on server-side processing as I don't feel it's necessary for my solution (it's only a dinky database) so basically I'd just like to know what I can use to catch the get request with my php
( i.e
if(isset($_GET['datatables']))
{ **build my json** }

If anyone could provide me with that, it would be very much appreciated, thanks :)

Replies

  • snarf2larfsnarf2larf Posts: 64Questions: 0Answers: 0
    You can call any page you want (on the same server) and as long as it responds with valid json for the table data it should work. If you want to send custom information along with the request look at fnServerParams
  • keirlav87keirlav87 Posts: 11Questions: 0Answers: 0
    I was just wondering how to catch the get request on teh server side?

    such as:

    $_GET['*what goes here*'];

    Thanks for replying
  • snarf2larfsnarf2larf Posts: 64Questions: 0Answers: 0
    You don't have to - You could simply make a datatables.php and call it like http://yoursite/datatables.php and it would work if it responded with correct json. If you want to add additional data sent to the server you would use fnServerParams and then what you check for is whatever you provide yourself.
  • keirlav87keirlav87 Posts: 11Questions: 0Answers: 0
    Thanks :) it's just the php file I will be catching the request with is like a central file that all requests are sent to, and then depending on the request the file catches it will initialise the correct class / function to service the request, if that makes sense
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    I don't really understand the question I'm afraid. DataTables doesn't specifically "announce" itself to an Ajax source - so there is not $_GET['isDataTables'] magic parameter.

    That shouldn't be needed though - DataTables can consume virtually any JSON data source: http://datatables.net/blog/Extended_data_source_options_with_DataTables

    Allan
  • snarf2larfsnarf2larf Posts: 64Questions: 0Answers: 0
    [quote]keirlav87 said: Thanks :) it's just the php file I will be catching the request with is like a central file that all requests are sent to, and then depending on the request the file catches it will initialise the correct class / function to service the request, if that makes sense[/quote]

    In your sAjaxSource you could set it up as 'http://yourserver/yourphp.php?datatable=true' or something like that. Then check $_GET['datatable']. I think that would work but I haven't tried it.
  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    Yup - what he said - that will work :-)

    Still better if you can avoid needing to do that thought...

    Allan
  • keirlav87keirlav87 Posts: 11Questions: 0Answers: 0
    snarfs answer will work I think, sorry for the ambiguity in the question I've not got an issue returning json that the datatable can handle - its just that the file i send my ajax request to is not just used for servicing the datatable ajax request, its like a main controller for alot of requests within the project, which then instantiates the class which holds the function which services the request - so i would like to be able to filter the get request that the datatable makes, just to trigger the process really. This would help keep my project consistent, but if necessary I can make a dedicated script for the datables.

    Thanks by the way for the quick replies, very much appreciated!
This discussion has been closed.