Wordpress Integration

Wordpress Integration

michaeljohnpricemichaeljohnprice Posts: 4Questions: 0Answers: 0
edited September 2011 in Announcements
I've been going through all the discussions on integrating DataTables with Wordpress and I can't seem to get the data to display properly. This is the perfect plugin for my project and I'm determined to get it to work and have spent the whole day troubleshooting. The closest I've come was using the discussion posted here:

http://www.datatables.net/forums/discussion/2317/installation-problem-with-datatables-server-side-processing-and-wordpress-3.0/p1

I followed the discussion and got nearly everything to work.

Here are some of the steps w/code that I've gotten through. If X's are there it's to keep it private.

1. I ran the server connection test (code below) and got back the proper number of rows I'm getting. When I ran the same test in my post, the results didn't print.

[code]

Replies

  • GregPGregP Posts: 485Questions: 7Answers: 0
    It's all about the AJAX call. You can't make that kind of AJAX call to a PHP resource from within Wordpress without jumping through some hoops, as I learned recently while trying to make an email contact form.

    In general, AJAX requests need to be passed through admin-ajax.php which despite its name isn't actually only for admin-related AJAX anymore.

    Using your above code, I can bet that if you inspect the GET request, the response will be a 404 page.

    I can't say I honestly understand how it all works, since the request is sent to admin-ajax.php (and you never actually need to add any code to admin-ajax.php) but somehow WordPress's black magic takes care of it to my astonishment. Here's the article I read in order to get me on track:

    Here's one resource that helped:

    http://codex.wordpress.org/AJAX_in_Plugins

    And here's the main one I drew upon:

    http://www.garyc40.com/2010/03/5-tips-for-using-ajax-in-wordpress/
  • GregPGregP Posts: 485Questions: 7Answers: 0
    Actually, reading this one just now and I think it's even clearer:

    http://www.1stwebdesigner.com/css/implement-ajax-wordpress-themes/

    Wordpress is able to capture the parameters sent to admin-ajax.php, and in the parameters you have sent your action. The action is defined in functions.php or wherever (I actually ended up implementing my function in a custom plugin)
  • michaeljohnpricemichaeljohnprice Posts: 4Questions: 0Answers: 0
    Thanks. I'll check this out and see if I can get it to work.
  • michaeljohnpricemichaeljohnprice Posts: 4Questions: 0Answers: 0
    I finally got it to work. The problem was that datatables.js was running before the jquery.js file and was throwing undefined functions. Once I resolved that, it worked perfectly. Instead of having datatables communicate with the server for now, I'm going to have the html pre generated with php and have datatables reconfigure the appearance. Guess you have to sleep on it sometimes.

    FYI...I did go through one of your ajax tutorials and think it'll come in handy in the near future.
  • GregPGregP Posts: 485Questions: 7Answers: 0
    Awesome to hear that you have a working solution for now! JavaScript timing is always interesting to resolve. In non-WP projects I've taken to using loaders (right now I prefer head.js but there are other good ones) to help organize loading as well as get performance boost.

    But I've never tried it in WordPress because I use WP's script enqueuing and I'm not sure how to get the two things to work alongside one another.
  • dnchancednchance Posts: 1Questions: 0Answers: 0
    I was able to insert mine into a page by adding a line with the Javascript includes at the top of the html... It seemed to work out pretty well after I figured out the paths everything was expecting.
  • michaeljohnpricemichaeljohnprice Posts: 4Questions: 0Answers: 0
    It was interesting because my wp theme does an enqueue call for JQuery but I think I needed a newer version.
  • serisseris Posts: 3Questions: 0Answers: 0
    Hi michaeljohnprice
    Is it possible to send me a working demo code? I am new to WP and tried hard for days but didn't make it work. THANKS in advance
This discussion has been closed.