how to use Jquery AJAX in Joomla Components?(如何在 Joomla 组件中使用 Jquery AJAX?)
问题描述
我正在 Joomla 开发网站,同时我遇到了一个问题,请帮助我解决以下问题
i m developing site in Joomla, meanwhile i stuck in a problem,please help me in below problem
这是我的组件文件夹结构
here is my folder structure for component
htdocs/Joomla/administrator/component/com_test/test.php,controller.php
models/test.php
controllers/test.php
views/test/view.html.php
view/test/tmpl/default.php
现在在 view.html.php
中,我创建了一个表单,其中我使用 jquery ajax 代码进行 usernmae 可用性检查
now in view.html.php
i created a form where i m using jquery ajax code for usernmae availability check
但我不知道如何组合所有内容以获得 usename 可用或不可用的结果
but i m not getting how do i combine all things to get the result that usename is available or not
这是我写在 test/view.html.php
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery("#username").change(function () {
var usr = jQuery("#username").val();
if (usr.length >= 2) {
jQuery("#status").html('<img src="bG9hZGVyLmdpZg==" align="absmiddle"> Checking availability...');
jQuery.ajax({
type: "POST",
url: "index.php?option=com_test&view=check_user",
data: "username=" + usr,
success: function (msg) {
jQuery("#status").ajaxComplete(function (event, request, settings) {
if (msg == 'OK') {
jQuery("#username").removeClass('object_error'); // if necessary
jQuery("#username").addClass("object_ok");
}
else {
jQuery("#username").removeClass('object_ok'); // if necessary
jQuery("#username").addClass("object_error");
jQuery(this).html(msg);
}
});
}
});
}
});
<script>
<form action="" method="post" name="addUserForm" id="addUserForm" >
<table width="100%" border="0" cellpadding="4" cellspacing="2">
<tr>
<th >User Name :</th>
<td ><input type="text" name="username" id="username" size="50">
<span id="status"></span>
</td>
</tr>
</table>
</form>
<小时>
我已经为上述操作创建了以下文件夹结构,请告诉我我哪里错了
i have created below folders structure for above action , please tell me where do i mistake
view/check_user/view.html.php
views/check_user/tmpl/default.php
check_user/view.html.php
<?php
// no direct access
defined('_JEXEC') or die('Restricted access');
jimport( 'joomla.application.component.view');
/**
* HTML View class for the advertising component
*/
class TestViewCheck_user extends JView
{
/**
* Default display function
*/
function display($tpl = null)
{
$testController = new TestController();
// Make an object of Main Model class contains Main functions
$testModel = $testController->getModel('test');
$userName = JRequest::getVar('username');
parent::display($tpl);
}
}
?>
但是当我运行这段代码时......为什么http://localhost/Joomla/includes/js/joomla.javascript.js
文件无限次运行..最后给出4个错误
but when i run this code...why
http://localhost/Joomla/includes/js/joomla.javascript.js
file runs infinite times.. and finally give 4 error
现在我必须修改/添加更多???请指导我....
now what i have to modify/add more??? please just guide me ....
参考任何有用的链接,教你一步一步地创建组件......这对我很有帮助
refer any useful link which teach to create component step by step ...it will be very helpful for me
非常感谢
推荐答案
所有前端代码都应该在您的 tmpl 中,因此您的 Ajax 内容也应该在那里.查看本教程,了解如何为 Joomla 制作 MVC 组件 http://www.joomladevuser.com/tutorials/components(死链接).
All front end code should be in your tmpl, so your Ajax stuff should be in there too. Check this tutorial out on how to make MVC components for Joomla http://www.joomladevuser.com/tutorials/components (deadlink).
这篇关于如何在 Joomla 组件中使用 Jquery AJAX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Joomla 组件中使用 Jquery AJAX?
- 从 PHP 中的输入表单获取日期 2022-01-01
- 正确分离 PHP 中的逻辑/样式 2021-01-01
- Laravel 仓库 2022-01-01
- 如何定位 php.ini 文件 (xampp) 2022-01-01
- Mod使用GET变量将子域重写为PHP 2021-01-01
- SoapClient 设置自定义 HTTP Header 2021-01-01
- 没有作曲家的 PSR4 自动加载 2022-01-01
- PHP Count 布尔数组中真值的数量 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 带有通配符的 Laravel 验证器 2021-01-01