joomla 中的 load() 添加部分表单 returns 404

load() in joomla to add part of form returns 404

我正在尝试使用 jQuery - AJAX load() 方法加载注册表单的一部分作为防止垃圾邮件的原始保护。我没有在 joomla 中使用 ajax 和 jquery 的经验,我怀疑这是这里的主要问题。

我试图用 https://www.w3schools.com/jquery/jquery_ajax_load.asp 中的代码修改注册表的现有 default.php 文件。它做了一些事情,但不是我想要的。 在加载我设置的单独文件内容时,它在选定的 DIV 中显示整个网页,并出现 404 错误。 这是实际的例子: https://ambicij.si/2019/index.php/davki/seminar-davki-v-podjetjih-in-poudarek-na-dohodnini-obdavcitev-razlicnih-izplacil-zdoh-2/individual-registration

如果您按 "External Content" 按钮,它将显示我所描述的内容。我想将提交按钮从 DIV gumbi 移动到外部文件,以便访问者必须在提交表单之前加载按钮。 下面是我输入 default.php

的代码
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
    jQuery(document).ready(function(){
        jQuery("button").click(function(){
          jQuery("#gumbi").load("test.html", function(responseTxt, statusTxt, xhr){
           if(statusTxt == "success")
               alert("External content loaded successfully!");
           if(statusTxt == "error")
               alert("Error: " + xhr.status + ": " + xhr.statusText);
          });
        });
       });
</script> 
 <button>Get External Content</button>
    <div id="gumbi" class="form-actions">
        <input type="button" class="<?php echo $btnPrimary; ?>" name="btnBack" value="<?php echo  JText::_('EB_BACK') ;?>" onclick="window.history.go(-1);" />
        <input type="submit" class="<?php echo $btnPrimary; ?>" name="btn-submit" id="btn-submit" value="<?php echo $buttonText;?>" />
        <img id="ajax-loading-animation" src="<?php echo JUri::base(true);?>/media/com_eventbooking/ajax-loadding-animation.gif" style="display: none;"/>

    </div>

这里是外部 test.html:

  <html>
    <p>test</p>
  </html>

如前所述,我想将代码从 test.html 加载到 div gumbi,但目前我得到的整个网页都出现 404 错误。由于问题没有解决,大家可以关注我的link.

您对 "test.html" 的 ajax 请求解析为 url:

https://ambicij.si/2019/index.php/davki/seminar-davki-v-podjetjih-in-poudarek-na-dohodnini-obdavcitev-razlicnih-izplacil-zdoh-2/test.html

但是您的 index.php 无法找到或加载 test.html 并响应 Http 302 重定向到错误页面。 302 重定向不是 http 错误,因此您的 ajax 调用将其视为成功,错误处理程序永远不会触发并且错误页面的内容已加载到您的 div.

可能 test.html 没有上传,或者您可能想检查 index.php 中的代码以确保它可以找到文件。