Forums

Database query with Ajax (5 posts)

  1. peterjharrison
    Member
    Posted 1 year ago #

    Hi,

    I was wondering if anyone could help me.

    I am trying to write a plugin and as part of the plugin I need to query the database using jQuery/Ajax from the front side of the website but im not sure how I write this in my plugin.

    I have read the following page Ajax in Plugins but im not sure how to do it.

    If some one could help me out that would be much appreciated.

    Many Thanks
    Pete

  2. guar
    Member
    Posted 1 year ago #

    Hi Pete, the codex page you linked also links to this: http://www.wphardcore.com/2010/5-tips-for-using-ajax-in-wordpress/

    Although it is counter-intuitive, you do need to be sending your requests from the javascript to the admin-ajax.php file. The hooks you define will be called from there, and from there your functions will be called.

    Example Hooks:

    // this hook is fired if the current viewer is not logged in
    add_action( 'wp_ajax_nopriv_myajax-submit', 'myajax_submit' );
    add_action( 'wp_ajax_myajax-submit', 'myajax_submit' );

    The hook/action name is determined by the action field in the ajax request. So if your action is called "myajax-submit" you'd use the two actions above. The second argument is the name of the function to call in your plugin.

  3. Mark / t31os
    Moderator
    Posted 1 year ago #

    These are about as easy as the examples can be, i personally like the examples shown here.
    http://ocaoimh.ie/make-your-wordpress-plugin-talk-ajax/

    The above is also one of the links at the bottom of the Ajax codex page.

    If you have problems implementing your ajax function, post your code into a pastebin and link it back here for us to look at..

  4. jimmyy
    Member
    Posted 1 year ago #

    guar I spent around 10hours on the http://www.wphardcore.com/2010/5-tips-for-using-ajax-in-wordpress/
    but with no luck.
    If you are not an experienced wordpress that article is of no use, because it addresses experienced users.
    The article does not mention explicitly all the files that are impacted nor does it have a full source code example.

    I left a polite question to the author to add an full example, but my request was not even admited on that blog page...

    I'll try Mark's advice and post back here.

    Thanks

  5. redgie
    Member
    Posted 1 year ago #

    Did anyone get anywhere with this?

Topic Closed

This topic has been closed to new replies.

About this Topic