Javascript函数“不存在”.语法错误,但看不到它

Javascript function "does not exist". Bad syntax but can't see it

本文关键字:不存在 看不到 错误 语法 函数 Javascript      更新时间:2023-09-26

javascript应该处理表单提交。但是,即使调用
script src="js/registerform.js"> 未捕获的引用错误:未定义 sendreg 。该函数称为 onclick。可以在尝试注册时在 www.r4ge.ro 上复制以及实时编辑。试过 jshint.com 但没有线索。

我将使用所需的任何剪裁进行编辑。

    function sendreg() {
          var nameie = $("#fname").val();
          var passwordie = $("#fpass").val();
          var emailie = $("#fmail").val();
          if (nameie == '' || passwordie == '' || emailie == '') {
             alert("Please fill all the forms before submitting!");
          } else {
             // Returns successful data submission message when the entered information is stored in database.
             $.post("http://r4ge.ro/php/register.php", {
                numeleluii: nameie,
                pass: passwordie,
                mail: emailie
             }, function(data) {
                alert(data);
                $('#form')[0].reset(); // To reset form fields
                setTimeout(fillhome, 1000);
             });
          }
    }
    function sendpass() {
       var oldpassw = $("#oldpass").val();
       var newpassw = $("#newpass").val();
       if (oldpassw == '' || newpassw == '') {
          alert("Please fill all the forms before submitting!");
       } else {
          // Returns successful data submission message when the entered information is stored in database.
          $.post("http://r4ge.ro/php/security.php", {
             xoldpass: oldpassw,
             xnewpass: newpassw
          }, function(data2) {
             alert(data2);
             $('#passform')[0].reset(); // To reset form fields
          });
       }
    }
    function sendmail()
    {
    var curpass = $("#curpass").val();
    var newmail = $("#newmail").val();
    if (curpass == '' || newmail == '') 
    {
        alert("Please fill all the forms before submitting!");
    } 
    else 
    {
        // Returns successful data submission message when the entered information is stored in database.
        $.post("http://r4ge.ro/php/security.php", {
        curpass: curpass,
        newmail: newmail
        }, function(data3) {
        alert(data3);
        $('#mailform')[0].reset(); // To reset form fields
        });
    }
    }

我在这里猜测,但是...我想你正在做类似的事情...<button onclick="sendreg">...

您将<script>放在代码的底部。只需将它们放在上面或使用$("#mybtn").click(sendreg)

尝试使用 $("#mybtn").click(sendreg) 而不是内联onclick

在 html 中调用脚本。 抱歉浪费时间。一个简单的
<script src="js/registerform.js"></script>修复了它。

那里没有语法错误,我在尝试页面时没有看到任何此类错误。

您收到的错误是无法进行跨域调用。对同一域执行请求:

$.post("http://www.r4ge.ro/php/register.php", {

或:

$.post("/php/register.php", {