Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
0 votes
in Plugins by
edited by

I am developing a new plugin "event-watcher-ajax" that is supposed to display incoming events life in a widget and on a page.

Now I try to ajax-call the page, however I get this error:

PHP Fatal error:  Can't use function return value in write context in /event-watcher-ajax/qa-event-watcher-page.php on line 64

CODE of the page:

        function process_request($request)
         // we received post data, so it should be the ajax call!
         if( qa_post_text('request') ) {
             // process and return
             // the return causes the error above!
      else {

        // default loading of page
        // preparation of output and stuff...

        // + jquery ajax call "$('#responsecontainer').load('".qa_self_html()."')...


Update: I am reading the post just once and it works: $transferString = qa_post_text('request');

But another problem occured: The ajax call to the plugin itself outputs all theme content (menu and stuff), even if I catch the post first and do not output $qa_content = qa_content_prepare();

Do I have to call a layer? What am I doing wrong?
Any help appreciated!


1 Answer

0 votes
selected by
Best answer

It's difficult to say without the actual code, but if you just want to output some basic text on the AJAX call, all you need to do is echo it directly then return. In your if statement, something like this:

echo 'The output';

Later on in the function you need to have this somewhere:

$qa_content = qa_content_prepare();
$qa_content['title'] = 'Page title';
// ...
return $qa_content;

Also, which line is line 64? That might help you identify the exact error.

Thanks for the feedback. The only issue that remains: Why is the ajax call receiving the entire theme setup and not only the lines I echo? ...
If you return null from the process_request() function of a page module, the page should be empty. You can see an example of this in the opensearch-support plugin that comes with Q2A.
I do the same with my chat room plugin too.
It works, awesome!

Problem was actually me. I used: $transferString = qa_post_text('request'); → but instead of "request" I was naming the param "hours". Changing this goes into my if($transferString !== null) ... and returns NULL.

Thank you both, great job!