我的joomla模块中无法运行ajax [英] Cannot have ajax working in my joomla module

查看:101
本文介绍了我的joomla模块中无法运行ajax的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对joomla开发还很陌生,我正在关注有关如何在新创建的模块中使用AJAX功能的教程.

I'm quite new to joomla development and I'm following a tutorial on how to use AJAX capability in my newly created module.

基本上,在我的tmpl/default.php中,我有:

Basically, in my tmpl/default.php I have:

<script>
function runButton() {
  alert("clicked");
  var url='http://127.0.0.1:4444/getData';
  var request = new Request({
                  url: url,
                  method:'get',
                  onSuccess: function(responseText){
                    document.getElementById('fields-container').innerHTML=  responseText;
                  }
                }).send();
</script>
<?php
  defined('_JEXEC') or die('Restricted access');
?>
<input type="button" value="Click Here for Ajax Call" onClick="runButton()",1000);"/>
  <div id="fields-container">
</div>

当我单击按钮时,将调用运行"方法,但是在Chrome调试器中出现以下错误:

When I click on the button, the "run" method is called, but I have the following error in Chrome debugger:

OPTIONS http://127.0.0.1:4444/getData Resource failed to load

在端口4444上侦听的进程是一个代理,它将从我的模块内启用跨域ajax调用.如果我指定'http://localhost:4444/getData'

The process listening on port 4444 is a proxy that will enable the cross domain ajax calls from within my module. I have thte same issue if I specify 'http://localhost:4444/getData'

有什么主意吗?

更新

这似乎与以下事实有关:跨端口http查询未启用(即使在同一主机上).有任何解决方法吗?

This seems to be linked to theb fact cross port http query is not enabled (even on the same host). Any workaround ?

推荐答案

您正在使用通常限制ajax的defined( '_JEXEC' ) or die( 'Restricted access' );.

You're using defined( '_JEXEC' ) or die( 'Restricted access' ); which usually restricts ajax.

如果还没有,则需要使用define('_JEXEC', 1);

If you haven't already, you will need to use define('_JEXEC', 1);

请注意,您需要使用 define ,而不是 defined

Notice that you need to use define, not defined

还请确保此代码位于ajax脚本之前.

Please also make sure that this code comes first, before the ajax script.

这篇关于我的joomla模块中无法运行ajax的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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