如何在我的TYPO3 Extbase Extension中获得AJAX呼叫? [英] How to get an AJAX call in my TYPO3 Extbase Extension?

查看:76
本文介绍了如何在我的TYPO3 Extbase Extension中获得AJAX呼叫?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很难做到这一点,我一直在寻找一些手册,但是它们似乎对我没有用(它们要么不够详细,要么我太愚蠢,可能两者兼而有之.)

I have trouble doing this, I've been looking for some manuals, but they don't seems to work for me (they're either or detailed enough or I'm too stupid, probably something from both).

所以我想通过某个事件从我的Fluid View HTML文件开始AJAX调用,然后它应该在某个控制器中执行操作并返回一些值(任何值暂时都可以,我只是不能在Extbase中使用AJAX时,似乎可以在这里进行任何操作.

So I want to start an AJAX call from my Fluid View HTML file by some event, then it should go for the action in some controller and return some value (any value would be fine for the moment, I just can't seem to get anything to work here when it comes to AJAX in Extbase).

推荐答案

没有详细信息,我只能猜测您的问题是什么

首先也是最重要的事情是...使用FireBug检查AJAX调用的问题是什么.可能是错误的URL(动作,控制器等...)或动作中的某些问题而未返回所需的输出. FireBug可让您检查其堆叠位置.

First and most important thing is ... using FireBug to check what the problem with AJAX call is. It can be just wrong URL (action, controller etc...) or some problem in your action which doesn't return required output. FireBug will allow you to check where it stacks.

但最有可能...

将JS/CSS代码直接写入到Fluid视图中时,要记住非常重要的一点,不幸的是,几乎从未提到过:

There is VERY important thing to remember while writing JS/CSS code directly into your Fluid view and unfortunately it's almost never mentioned:

Fluid使用大括号表示字符串是变量:{someVar},因此,如果将AJAX或其他JavaScript函数放入Fluid模板中,则很可能将其视为Fluid变量.此示例粘贴到模板:

Fluid uses braces to indicate that the string is a variable: {someVar}, therefore if you put AJAX or other JavaScript function into the Fluid template it will be most probably considered just as Fluid variable. This sample pasted to the template:

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

将被渲染为:

$.ajax(Array);

解决方案:

直接在模板中转义很难,因此,将所有JavaScript保存到扩展名的Resources/Public目录下的单独文件中,并使用常见的HTML标记包含它肯定更容易:

Escaping it directly in the template is hard, therefore it's definitely easier just to save all your JavaScript into separate file under Resources/Public directory of your extension, and include it with common HTML tag:

<script type="text/javascript" src="typo3conf/ext/yourext/Resources/Public/ajaxFunctions.js"></script>

这篇关于如何在我的TYPO3 Extbase Extension中获得AJAX呼叫?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆