wpXtreme / wpdk

WordPress Development Kit
http://wpxtreme.github.io/wpdk/
Other
78 stars 19 forks source link

Get Ajax request #31

Closed Mte90 closed 10 years ago

Mte90 commented 10 years ago

I'm following this example but it's not explained the content of WPDKAjaxResponse(). I want use ajax for custom request but in the request the result is 0. I have written for test echo 123 but i not get this result. https://github.com/wpXtreme/wpdk/wiki/WPDK-Ajax

gfazioli commented 10 years ago

@Mte90 For example, starting from https://github.com/wpXtreme/wpdk/wiki/WPDK-Ajax:

<?php

    /**
     * Description
     *
     * @brief Brief
     *
     * @return string
     */
    public function my_ajax_action()
    {
      // Prepare response
      $response = new WPDKAjaxResponse();

      // Your code...

      if( $some_error ) {
           $response->error = 'an error....';
           $response->json();
      }

      // If all ok, you can choose any WPDKAjaxResponse property as

      $response->data[ 'my_data' ] = 'what you want';

      // Or....
      $response->data = array( ... );

      // Or....
      $obj = new stdClass(); $obj->prop = 123;
      $response->data = $obj;

      // ....

      $response->json();
    }
?>

Let me know if all works
Mte90 commented 10 years ago

Ok i have found the problem. In the main class that extend WPXPlugin the public function need to call the class for the ajax.

/**
     * Catch for ajax
     *
     * @brief Ajax
     */
    public function ajax() {
        MyAjaxClass::init();
    }

In the wiki this part it's missing :-)