0

While I managed to get a working AJAX call, it won't works with my already created actions, not on a newly created one.

My Typoscript looks like this:


    
    lib.AJAXPrototype= PAGE
    lib.AJAXPrototype {
      typeNum = 896571
      config {
        disableAllHeaderCode = 1
        xhtml_cleaning = 0
        admPanel = 0
              debug = 0
              no_cache = 1
        additionalHeaders = Content-type:text/html
      }
    }

    AJAX_Plugintyp < lib.AJAXPrototype
    AJAX_Plugintyp {
      typeNum = 89657201
      10 < tt_content.list.20.myext_myplugin1
    }

My AJAX call looks like this:


    $.ajax({
      url: "index.php",
      data: "tx_myext_myplugin1[controller]=Mycontroller1&tx_myext_myplugin1[action]=ajax&type=89657201",
      success: function(result) {
        alert(result);
      }
    });

My ajaxAction:


          /**
         * action ajax
         *
         * @return void
         */
        public function ajaxAction() {
            $test = 'sometext';
            $this->view->assign('test', $test);
        }
    

My Ajax.html (View/Output):


    <f:section name="main">
    <f:flashMessages />
    <div id="ajaxd">{test}</div>
    </f:section>

I won't get anyoutput from this, I created this Action just for the Ajax Output. However, if I use any other controller/action combination, it works! What could I possibly have done wrong with the new Action?

user828591
  • 1,212
  • 2
  • 17
  • 32

2 Answers2

2

Two things about ajax and Extbase

First Placing JS directly in the view often fails, because Fluid is trying to parse JavaScript's arrays as own array/variable. Very uncomfortable. Solution is placing JS in separate files (therefore I asked you a question about this). See this question/answer

Second thing is Firebug (or other similar tool). With ultra long paths of Extbase links it's easy to make some annoying mistake in it, and then you need to compare carefully char by char.

Firebug will help you to find AJAX problem really fast, just open it switch to the Net tab and then you'll see what is sent with ajax after some action and what it returns. Most probably you were receiving something like:

Uncaught TYPO3 Exception:
The action "xxxxx" (controller "Yyyy") is not allowed by this plugin...

But the only way to check it is debugging with Firebug :)

Community
  • 1
  • 1
biesior
  • 55,576
  • 10
  • 125
  • 182
  • Thanks again, I remember you said this in that other question, oddly enough, the Net-tab wasn't activated, so I can only check it in the future. But as I wrote, it has already been solved (somehow). Thanks for the help though, I will keep in mind to put the JS into an external file right from the beginning from now on. Meanwhile, do you know how to get values from database fields from within the action and submit it as an array back to AJAX? That'd be my next problem :) – user828591 May 23 '12 at 12:32
  • Some of Firebug's tabs are disabled by default, if you'll click it it will be enabled till next manual disabling. About DB values: yeap, I know the trick, but it's better idea to create new Question and demonstrate what do you want to achieve. – biesior May 23 '12 at 13:02
  • I just wrote it, probably too late, but I'm not in a big hurry :) – user828591 May 23 '12 at 13:39
0

Okay, so RIGHT NOW it works. This might sound crazy, but I didn't really change anything for it to work.

I did forget to add it to the ext_localconf.php:


    
        Tx_Extbase_Utility_Extension::configurePlugin(
            $_EXTKEY,
            'Myplugin1',
            array(
                'Mycontroller' => 'list, ajax',
            ),
            // non-cacheable actions
            array(
                'Mycontroller' => 'list, ajax',
            )
        );
        

However, I did this yesterday and afterwards, it didn't work. Today I tried some random editing in the typoscript again (changing pagetype etc.) and suddenly it worked! However, I went back to the exact state I had yesterday and it still worked. I'm confused, no idea if I just had to rearrange the typoscript or if it had to write it again for some reason, but I'm happy it works now!

user828591
  • 1,212
  • 2
  • 17
  • 32