沃梦达 / 编程问答 / php问题 / 正文

如何在 Joomla 组件中使用 Jquery AJAX?

how to use Jquery AJAX in Joomla Components?(如何在 Joomla 组件中使用 Jquery AJAX?)

本文介绍了如何在 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="loader.gif" align="absmiddle">&nbsp;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?

基础教程推荐