【发布时间】:2011-03-10 14:33:17
【问题描述】:
我正在 Joomla 中开发网站,同时我遇到了一个问题,请帮助我解决以下问题
这是我的组件文件夹结构
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 代码进行用户名可用性检查
但我不知道如何将所有东西结合起来以获得用户名可用或不可用的结果
这是我写在 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="loader.gif" 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>
我已经为上述操作创建了下面的文件夹结构,请告诉我我哪里出错了
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 个错误
现在我必须修改/添加更多内容???请指导我....
参考任何有用的链接,教你逐步创建组件...这对我很有帮助
非常感谢
【问题讨论】: